Skip to content

Commit a2ccff8

Browse files
authored
fix: false positive triggered by HTML inside comments in no-html (#592)
fix: false positive triggered by comments in `no-html`
1 parent 90e3b86 commit a2ccff8

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/rules/no-html.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Imports
88
//-----------------------------------------------------------------------------
99

10-
import { lineEndingPattern } from "../util.js";
10+
import { lineEndingPattern, stripHtmlComments } from "../util.js";
1111

1212
//-----------------------------------------------------------------------------
1313
// Type Definitions
@@ -89,10 +89,12 @@ export default {
8989

9090
return {
9191
html(node) {
92+
const text = stripHtmlComments(sourceCode.getText(node));
93+
9294
/** @type {RegExpExecArray} */
9395
let match;
9496

95-
while ((match = htmlTagPattern.exec(node.value)) !== null) {
97+
while ((match = htmlTagPattern.exec(text)) !== null) {
9698
const fullMatch = match[0];
9799
const { tagName } = match.groups;
98100
const firstNewlineIndex =

tests/rules/no-html.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ ruleTester.run("no-html", rule, {
2828
"Hello world!",
2929
" 1 < 5",
3030
"<!-- comment -->",
31+
"<!-- <h1> -->",
32+
'<!-- <div id="foo"> -->',
33+
"<!-- abcdefg <abcdefg> -->",
3134
dedent`\`\`\`html
3235
<b>Hello world!</b>
3336
\`\`\``,

0 commit comments

Comments
 (0)