Skip to content

Commit

Permalink
[Fix] jsx-curly-brace-presence: fix multiline comment case
Browse files Browse the repository at this point in the history
Fixes #2716.
  • Loading branch information
ljharb committed Aug 12, 2020
1 parent a77c0d1 commit bac0ec3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/rules/jsx-curly-brace-presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ module.exports = {
return /['"]/.test(value);
}

function containsMultilineComment(value) {
return /\/\*/.test(value);
}

function escapeDoubleQuotes(rawStringValue) {
return rawStringValue.replace(/\\"/g, '"').replace(/"/g, '\\"');
}
Expand Down Expand Up @@ -238,6 +242,7 @@ module.exports = {
(JSXExpressionNode.parent.type === 'JSXAttribute' && !isWhiteSpaceLiteral(expression))
|| !isLiteralWithTrailingWhiteSpaces(expression)
)
&& !containsMultilineComment(expression.value)
&& !needToEscapeCharacterForJSX(expression.raw, JSXExpressionNode) && (
jsxUtil.isJSX(JSXExpressionNode.parent)
|| !containsQuoteCharacters(expression.value)
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/jsx-curly-brace-presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,16 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
};
`,
options: [{props: 'never', children: 'never'}]
},
{
code: `
import React from "react";
const Component = () => {
return <span>{"/*"}</span>;
};
`,
options: [{props: 'never', children: 'never'}]
}
],

Expand Down

0 comments on commit bac0ec3

Please sign in to comment.