fix(lint): treat an HTML comment as a text boundary outside inline elements - #1140
Merged
Merged
Conversation
…ements An HTML comment left closedInline untouched, so clean() hit neither arm of its whitespace rule and the following text lost its leading space. 'on <!-- TODO --> a' fused to 'ona' and raised a false spelling alert. Set closedInline on a comment only when no inline element is open. Inside an open inline element the opening tag is still the boundary, so its padding (vale-cli#1052) is preserved. Fixes vale-cli#882
The fixture already covered a comment inside an open <em>, but the case still asserted no output, so the regression it guards against would not have failed the suite.
Member
|
Thanks! |
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.
An HTML comment between two words causes a false spelling alert:
Removing the comment yields no alerts.
lintHTMLTokenssetsclosedInlinein theEndTagTokenbranch and clears it inStartTagToken, but aCommentTokenleaves it untouched. Its consumer isclean(), whose whitespace decision is(closedInline && spaced) || (!closedInline && inline && !starter). After a comment both flags are stale-false, so neither arm fires, the following text loses its leading space, andon+afuse intoona.Setting
closedInlineon a comment only fixes the outer case: a comment right after an inline opening tag is not a closed boundary, and asserting one there disables the#1052padding. That loses real alerts and invents words —A sona<em><!--c-->ta</em>fuses tosonata, so the genuinesonaalert disappears.So the flag is set only when no inline element is open. Inside one, the opening tag remains the boundary and its padding is preserved.
Fixes #882
Verification
Built before/after binaries and compared:
on <!-- TODO --> a/sonata2:2 'ona'A sona<em><!--c-->ta</em> here.1:3 'sona'1:3 'sona'A sona<b><!-- c --></b>ta here.in <code><!--c-->x</code> forword<!--c-->swordswordsA <!-- c --> sonaAsona)1:14 'sona'The last row is a second bug the same change fixes: text after a comment at the start of a fragment was being fused to the preceding word.
go build ./...andgo test ./...pass. The regression case is intestdata/e2e/comments.yamlalongside the existing#1001comment case, and it fails without the fix.Note
lintHTMLTokensis shared across html/md/adoc/rst/org/dita/xml, so this affects all of them; I checked the.htmlpath behaves the same.