Repository navigation
Add Polytypo.analyze, the reported-edits entry point - #4
Merged
Merged
Conversation
Implements spec 1.3.0's spec/rules/analyze.md (polytypo/polytypo@691c180, canonical issue #15), porting polytypo-js@1a2ef57. Same pipeline as .transform, reporting what it would do instead of doing it: Polytypo.analyze(%q{Wait... "really"?}, locale: "en-US") # => [#<data Polytypo::Change rule_id="ellipsis", start=4, end=7, before="...", after="…">, …] Nothing in the engine changed to support it. Rules already produce edits and the pipeline already applies them, so the whole feature is one structure: an origin map travelling alongside the code-point array (engine/origin.rb), holding the input offset each code point came from. A same-length replacement keeps its origins position by position, which is what makes a converted space still point at the space it converted. The mode adapters are where this could quietly go wrong, and analyze.md §6 says so: in html and markdown the rules run over the marker-joined concatenation of spans, so reporting those offsets would pass every text-mode test and be useless to a caller. Spans.origin_of_spans maps them back to document offsets, asserted in a three-span document as well as a single-span one, so a doubled or dropped marker origin cannot hide. Change is a Data defined in the Polytypo namespace rather than in Engine: it is public API, and #inspect prints the namespace it was defined in, which is the one a reader will copy. Nineteen examples, including A3 against the entire vendored fixture corpus — empty list exactly when in == out — and analyze.md §5's French overlap at the spec's own offsets, spaces at 3–4 and nbsp at 4–4 on `Oui : non`. Full suite 1122 examples, 0 failures, including the packaging spec that installs the built gem into a clean GEM_HOME — the one that catches a new lib/ file the gemspec's git-ls-files manifest would otherwise ship without. .transform's behaviour is untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Sep 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports spec 1.3.0's
spec/rules/analyze.md(canonical issue polytypo/polytypo#15), after polytypo/polytypo-js#13, polytypo/polytypo-python#4 and polytypo/polytypo-go#4.Polytypo.analyzeruns the identical pipeline as.transformand reports what it would do instead of doing it. Contract A1–A5: same arguments and same error codes, pure, empty exactly when.transformreturns the input unchanged, only rules enabled for the call, code-point offsets inside the input. The decomposition into records is explicitly not contract (analyze.md §4), so no fixture asserts it and the five runtimes are not required to agree on it.Nothing in the engine changed. The whole feature is an origin map travelling beside the code-point array (
lib/polytypo/engine/origin.rb).Two details worth a look in review:
Changelives in thePolytyponamespace, notPolytypo::Engine, even thoughEngine::Originbuilds it —#inspectprints the defining namespace, and that is the name a reader copies out of a console session.html/markdownthe rules run over the marker-joined span concatenation; reporting those offsets passes every text-mode test and is useless to a caller (analyze.md §6).Spans.origin_of_spansmaps them back, asserted in a three-span document too.Checks: full suite 1122 examples, 0 failures, 5 pending (the
mdxskips), run locally on Ruby 3.3.8 — includingspec/packaging_spec.rb, which builds and installs the gem into a cleanGEM_HOMEand caughtorigin.rbbeing missing from the gemspec'sgit ls-filesmanifest before it could reach CI. RuboCop was not run locally (the gem does not build on this machine); CI covers it..transform's behaviour is untouched.🤖 Generated with Claude Code