Skip to content

Commit fe708e1

Browse files
committed
[Fix] jsx-curly-brace-presence: avoid warning on curlies containing quote characters
Fixes #3214
1 parent 7f44ecc commit fe708e1

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
55

66
## Unreleased
77

8+
### Fixed
9+
* [`jsx-curly-brace-presence`]: avoid warning on curlies containing quote characters ([#3214][] @ljharb)
10+
11+
[#3214]: https://github.com/yannickcr/eslint-plugin-react/issues/3214
12+
813
## [7.29.1] - 2022.02.25
914

1015
### Fixed

lib/rules/jsx-curly-brace-presence.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ const messages = {
3939
module.exports = {
4040
meta: {
4141
docs: {
42-
description:
43-
'Disallow unnecessary JSX expressions when literals alone are sufficient '
44-
+ 'or enfore JSX expressions on literals in JSX children or attributes',
42+
description: 'Disallow unnecessary JSX expressions when literals alone are sufficient or enfore JSX expressions on literals in JSX children or attributes',
4543
category: 'Stylistic Issues',
4644
recommended: false,
4745
url: docsUrl('jsx-curly-brace-presence'),
@@ -274,13 +272,11 @@ module.exports = {
274272
reportUnnecessaryCurly(JSXExpressionNode);
275273
} else if (
276274
expressionType === 'TemplateLiteral'
277-
&& expression.expressions.length === 0
278-
&& expression.quasis[0].value.raw.indexOf('\n') === -1
279-
&& !isStringWithTrailingWhiteSpaces(expression.quasis[0].value.raw)
280-
&& !needToEscapeCharacterForJSX(expression.quasis[0].value.raw, JSXExpressionNode) && (
281-
jsxUtil.isJSX(JSXExpressionNode.parent)
282-
|| !containsQuoteCharacters(expression.quasis[0].value.cooked)
283-
)
275+
&& expression.expressions.length === 0
276+
&& expression.quasis[0].value.raw.indexOf('\n') === -1
277+
&& !isStringWithTrailingWhiteSpaces(expression.quasis[0].value.raw)
278+
&& !needToEscapeCharacterForJSX(expression.quasis[0].value.raw, JSXExpressionNode)
279+
&& !containsQuoteCharacters(expression.quasis[0].value.cooked)
284280
) {
285281
reportUnnecessaryCurly(JSXExpressionNode);
286282
} else if (jsxUtil.isJSX(expression)) {

tests/lib/rules/jsx-curly-brace-presence.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
454454
{
455455
code: `<App horror={<div />} />`,
456456
options: [{ propElementValues: 'ignore' }],
457+
},
458+
{
459+
code: `
460+
<script>{\`window.foo = "bar"\`}</script>
461+
`,
457462
}
458463
)),
459464

tests/lib/rules/no-unescaped-entities.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,25 @@ ruleTester.run('no-unescaped-entities', rule, {
315315
],
316316
},
317317
],
318+
},
319+
{
320+
code: `
321+
<script>window.foo = "bar"</script>
322+
`,
323+
errors: [
324+
{
325+
messageId: 'unescapedEntityAlts',
326+
data: { entity: '"', alts: '`&quot;`, `&ldquo;`, `&#34;`, `&rdquo;`' },
327+
line: 2,
328+
column: 30,
329+
},
330+
{
331+
messageId: 'unescapedEntityAlts',
332+
data: { entity: '"', alts: '`&quot;`, `&ldquo;`, `&#34;`, `&rdquo;`' },
333+
line: 2,
334+
column: 34,
335+
},
336+
],
318337
}
319338
)),
320339
});

0 commit comments

Comments
 (0)