Skip to content

Commit e587329

Browse files
authored
fix(lint): treat an HTML comment as a text boundary outside inline elements (#1140)
* fix(lint): treat an HTML comment as a text boundary outside inline elements 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 (#1052) is preserved. Fixes #882 * test(lint): pin the inline-element case for #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. --------- Co-authored-by: VXNCXNX <VXNCXNX@users.noreply.github.com>
1 parent 4691bd3 commit e587329

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎internal/lint/ast.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ func (l *Linter) lintHTMLTokens(f *core.File, raw []byte, offset int) error { //
163163
}
164164
}
165165
} else if tokt == html.CommentToken {
166+
// A comment, like a closed inline element, is a source-faithful
167+
// boundary: trust the next text's own whitespace (#882). Inside a
168+
// still-open inline element the opening tag remains the boundary,
169+
// so leave the state alone and keep its padding (#1052).
170+
if !inline {
171+
closedInline = true
172+
}
166173
f.UpdateComments(txt)
167174
walker.update(txt, tokt)
168175
} else if tokt == html.TextToken {

‎testdata/e2e/comments.yaml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,12 @@ cases:
100100
exit: 0
101101
want: |
102102
issue1001.md:5:28:demo.Ending-Preposition:Don't end a sentence with 'of.'
103+
104+
- name: inline-comment-spacing
105+
about: "#882 -- text after a comment keeps its own leading space instead of
106+
fusing with the text before it; inside a still-open inline element the
107+
opening tag stays the boundary, so `sona` isn't fused into `sonata`"
108+
args: issue882.md
109+
exit: 1
110+
want: |
111+
issue882.md:4:3:Vale.Spelling:Did you really mean 'sona'?

‎testdata/fixtures/comments/.vale.ini‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ demo.SentenceCaseAny = NO
1212

1313
[test2.mdx]
1414
CommentDelimiters = {/*, */}
15+
16+
[issue882.md]
17+
BasedOnStyles = Vale
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
on <!-- TODO --> a
2+
sonata
3+
4+
A sona<em><!--c-->ta</em> here.

0 commit comments

Comments
 (0)