fix: suppress unintended_html_in_doc_comment for spec-prose angle brackets#215
Open
nottmey wants to merge 2 commits into
Open
fix: suppress unintended_html_in_doc_comment for spec-prose angle brackets#215nottmey wants to merge 2 commits into
nottmey wants to merge 2 commits into
Conversation
…ckets Spec descriptions copy prose verbatim into dartdoc, where `<x>` is parsed as an HTML tag start even when it is not HTML. Backstage's catalog spec describes an entity ref as `location:default/generated-<sha1hex>`, and `<sha1hex>` reads as an (unclosed) tag start to dartdoc, tripping `very_good_analysis`'s `unintended_html_in_doc_comment` on every consumer. Mirrors PR eseidel#138's `comment_references` handling: spec prose that trips dartdoc's parser should be sanitized at the generator boundary rather than forcing every consumer to hand-suppress. Adds a `maybeAddUnintendedHtmlIgnore` emit-time helper (analogous to `maybeAddCommentReferencesIgnore`) that prepends `// ignore_for_file: unintended_html_in_doc_comment` to any file whose `///` doc comments carry an angle-bracket token dartdoc would parse as an HTML tag start. Detection matches `<` immediately followed by an ASCII letter or by `/`+letter — the shapes dartdoc's HTML parser treats as element starts. Plain comparison prose like `a < b` or `i < 0` does not match because the character after `<` is a space or digit, not a letter. Spec that surfaced this: https://github.com/backstage/backstage/blob/master/plugins/catalog-backend/src/schema/openapi.yaml Co-authored-by: Cursor <cursoragent@cursor.com>
Two follow-ups to 4a74e4e: - Emitted `unintended_html_in_doc_comment` ignore block referenced Backstage-specific jargon (`entity-ref examples like \`location:default/generated-<sha1hex>\``), which leaks one consumer's vocabulary into every other consumer's generated files. Genericize to `placeholder tokens like \`<sha1hex>\`` — same shape, no domain-specific wording. Mirrors the existing `commentReferencesIgnoreBlock` which already stays generic ("placeholder text, ALL_CAPS tokens, license templates"). The internal dartdoc on the const keeps the Backstage reference for maintainer provenance, matching `commentReferencesIgnoreBlock`'s citation of github's code-of-conduct. - Detection regex `<(?:[A-Za-z]|/[A-Za-z])` is a verbose way to write `</?[A-Za-z]` — same match set, one fewer alternation. Co-authored-by: Cursor <cursoragent@cursor.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
Spec descriptions copy prose verbatim into dartdoc, where
<x>is parsed as an HTML tag start even when it is not HTML. Backstage's catalog spec describes an entity ref aslocation:default/generated-<sha1hex>, and<sha1hex>reads as an (unclosed) tag start to dartdoc, trippingvery_good_analysis'sunintended_html_in_doc_commenton every consumer package.Fix
Mirrors PR #138's
comment_referenceshandling: spec prose that trips dartdoc's parser should be sanitized at the generator boundary rather than forcing every consumer to hand-suppress. Adds amaybeAddUnintendedHtmlIgnoreemit-time helper (analogous tomaybeAddCommentReferencesIgnore) that prepends// ignore_for_file: unintended_html_in_doc_commentto any file whose///doc comments carry an angle-bracket token dartdoc would parse as an HTML tag start.Wired into
maybeAddIgnoreDirectivesalongside the existing long-line andcomment_referenceshelpers, so it runs at file-emit time on every space_gen-emitted file. Hand-written templates bypass it (same design rationale as #138).Detection matches
<immediately followed by an ASCII letter or by/+letter — the shapes dartdoc's HTML parser treats as element starts. Plain comparison prose likea < bori < 0does not match because the character after<is a space or digit, not a letter.Spec that surfaced this
Backstage's catalog OpenAPI spec:
https://github.com/backstage/backstage/blob/master/plugins/catalog-backend/src/schema/openapi.yaml
Schema excerpt (
Location.entityRef):Generated dartdoc (
location.dart):Before this fix:
dart analyzeon the generated package reportsinfo - lib/models/location.dart:45:34 - Angle brackets will be interpreted as HTML.After this fix:No issues found!Test plan
maybeAddUnintendedHtmlIgnoregroup totest/render/formatting_test.dart— 7 tests covering: pass-through with no angle brackets, prepend on tag-like<sha1hex>, no match on//plain comments, no fire on comparison prose (a < b,i < 0), fire on closing-tag</foo>, idempotency, indented member docs.dart test test/render/formatting_test.dart— all formatting tests pass.dart test(full suite) — 554 tests pass, no regressions.bin/space_gen.dartagainst the Backstage catalog spec;dart analyzeon the generated package reportsNo issues found!(previously 1unintended_html_in_doc_commentinfo).Made with Cursor