Skip to content

Commit 02ac5ce

Browse files
authored
Merge pull request #1527 from jomasti/issue-1517
Fix bad report by jsx-no-comment-textnodes
2 parents f36b0fa + c7cb6b5 commit 02ac5ce

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/rules/jsx-no-comment-textnodes.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ module.exports = {
3434

3535
return {
3636
Literal: function(node) {
37-
if (/^\s*\/(\/|\*)/m.test(node.value)) {
37+
const sourceCode = context.getSourceCode();
38+
// since babel-eslint has the wrong node.raw, we'll get the source text
39+
const rawValue = sourceCode.getText(node);
40+
if (/^\s*\/(\/|\*)/m.test(rawValue)) {
3841
// inside component, e.g. <div>literal</div>
3942
if (node.parent.type !== 'JSXAttribute' &&
4043
node.parent.type !== 'JSXExpressionContainer' &&

tests/lib/rules/jsx-no-comment-textnodes.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ ruleTester.run('jsx-no-comment-textnodes', rule, {
131131
<Foo title={'foo' /* valid */}/>
132132
`,
133133
parser: 'babel-eslint'
134+
},
135+
{
136+
code: '<pre>&#x2F;&#x2F; TODO: Write perfect code</pre>'
137+
},
138+
{
139+
code: '<pre>&#x2F;&#x2F; TODO: Write perfect code</pre>',
140+
parser: 'babel-eslint'
141+
},
142+
{
143+
code: '<pre>&#x2F;&#42; TODO: Write perfect code &#42;&#x2F;</pre>'
144+
},
145+
{
146+
code: '<pre>&#x2F;&#42; TODO: Write perfect code &#42;&#x2F;</pre>',
147+
parser: 'babel-eslint'
134148
}
135149
],
136150

0 commit comments

Comments
 (0)