Repository navigation
fix(comments): make reflow settle in one pass and keep URLs and sentences intact - #715
Merged
Merged
Conversation
…nces intact Add fast-check property tests for parseAndTransformComments (changed flag, code outside comments, idempotence on realistic prose, comment words kept whole) and fix the bugs they found: - A NOTE sentence ended at any ".", "!" or "?", so a URL inside it was split. - A word ending in "NOTE:" (FOOTNOTE:) dropped the text before it. - A wrap that started a line with "-", "+", "1.", a fence, a tag, "note:", or (in // comments) a directive changed the comment on the next pass; a wrapped line that looked like a heading did too. - A NOTE sentence that wrapped got its tail joined to the next sentence on the second pass, and a sentence split off before a NOTE got its period late. - With --merge-line-comments, a long // line took two runs to become JSDoc. - Merging could start in the middle of an ineligible // comment. - An unclosed code fence grew by one blank line on every run. Remove the unreachable "explanatory group after a ;" heuristic: ";" is already in the merge eligibility pattern. Across the 2,040 TypeScript files in the seven ~/projects repos, 21 needed more than one pass before; none do now. Seven files that are stable today change once (multi-sentence NOTE paragraphs settle on one layout). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Adds property-based tests (fast-check) for
parseAndTransformCommentsand fixes the bugs they found. The most visible: a URL inside aNOTE:sentence was split,FOOTNOTE:deleted the sentence before it, and several inputs needed two or more runs to settle, which is why we re-runcommentsuntil it reports no changes.Properties (
lib.property.test.ts)changedis true exactly when the output differsrealistic-source.ts)Each property was checked against a one-line mutant of
lib.tsthat it must catch, and its comment records the mutant. Idempotence is scoped to realistic prose; degenerate input such as an empty or stackednote:can still need two passes. The minimal inputs for each bug are plain cases inlib.regressions.test.ts, and each one fails on the code it fixes.Fixes (
lib.ts).,!or?followed by a space or the end of the text, so URLs and regex tokens stay whole.NOTE:(for exampleFOOTNOTE:) no longer drops the text before it.-,+,1., a fence, a tag,note:, or a directive in//comments. A wrapped line that looks like a heading is joined to its neighbor.--merge-line-comments, merging runs again after wrapping, so a long//line settles in one run.//comment.qualifiesExplanatoryAfterStatement, which never ran:;is already in the merge eligibility pattern.Effect on existing code
I ran the old and new versions over the 2,040 TypeScript files in clubroad, episodia, sassysaint, auth0-thin, ui-components, ui-icons and node-cli with
--merge-line-commentsat width 80:One existing test changed: it expected the first-pass output without the period that the old code added on its second pass.
Test plan
pnpm exec vitest run --globalsinpackages/comments: 64 tests passbiome check,tsc --noEmit, andcomments --merge-line-commentson the touched files are clean🤖 Generated with Claude Code