Skip to content

Commit f818096

Browse files
taozhou-gleanljharb
authored andcommitted
Revert "[Fix] jsx-curly-brace-presence: handle single and only expression template literals"
This reverts commit 099b14c / #3538. Fixes #3607.
1 parent 1a3a17a commit f818096

File tree

3 files changed

+7
-26
lines changed

3 files changed

+7
-26
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
77

88
### Fixed
99
* [`require-default-props`]: fix config schema ([#3605][] @controversial)
10+
* [`jsx-curly-brace-presence`]: Revert [#3538][] due to issues with intended string type casting usage ([#3611][] @taozhou-glean)
1011

12+
[#3611]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3611
1113
[#3605]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3605
1214

1315
## [7.33.0] - 2023.07.19

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

-10
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ module.exports = {
131131
return containsLineTerminators(text) && text.trim() === '';
132132
}
133133

134-
function isSingleExpressionTemplateLiteral(child) {
135-
return child.type === 'TemplateLiteral' && child.expressions.length === 1 && child.quasis.map((quasis) => quasis.value.raw).join('') === '';
136-
}
137-
138134
function wrapNonHTMLEntities(text) {
139135
const HTML_ENTITY = '<HTML_ENTITY>';
140136
const withCurlyBraces = text.split(HTML_ENTITY_REGEX()).map((word) => (
@@ -181,9 +177,6 @@ module.exports = {
181177
if (jsxUtil.isJSX(expression)) {
182178
const sourceCode = context.getSourceCode();
183179
textToReplace = sourceCode.getText(expression);
184-
} else if (isSingleExpressionTemplateLiteral(expression)) {
185-
const sourceCode = context.getSourceCode();
186-
textToReplace = `{${sourceCode.getText(expression.expressions[0])}}`;
187180
} else {
188181
const expressionType = expression && expression.type;
189182
const parentType = JSXExpressionNode.parent.type;
@@ -286,9 +279,6 @@ module.exports = {
286279
&& !containsQuoteCharacters(expression.quasis[0].value.cooked)
287280
) {
288281
reportUnnecessaryCurly(JSXExpressionNode);
289-
} else if (
290-
isSingleExpressionTemplateLiteral(expression)) {
291-
reportUnnecessaryCurly(JSXExpressionNode);
292282
} else if (jsxUtil.isJSX(expression)) {
293283
reportUnnecessaryCurly(JSXExpressionNode);
294284
}

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

+5-16
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,14 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
469469
features: ['no-ts'],
470470
options: ['never'],
471471
},
472+
// legit as this single template literal might be used for stringifying
472473
{
473-
code: '<App label={`${label}${suffix}`} />',
474-
options: [{ props: 'never' }],
474+
code: '<App label={`${label}`} />',
475+
options: ['never'],
475476
},
476477
{
477-
code: '<App>{`${label}${suffix}`}</App>',
478-
options: [{ children: 'never' }],
478+
code: '<App>{`${label}`}</App>',
479+
options: ['never'],
479480
}
480481
)),
481482

@@ -939,18 +940,6 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
939940
errors: [{ messageId: 'unnecessaryCurly' }],
940941
options: [{ props: 'never', children: 'never', propElementValues: 'never' }],
941942
features: ['no-ts'],
942-
},
943-
{
944-
code: '<App label={`${label}`} />',
945-
output: '<App label={label} />',
946-
errors: [{ messageId: 'unnecessaryCurly' }],
947-
options: [{ props: 'never', children: 'never', propElementValues: 'never' }],
948-
},
949-
{
950-
code: '<App>{`${label}`}</App>',
951-
output: '<App>{label}</App>',
952-
errors: [{ messageId: 'unnecessaryCurly' }],
953-
options: [{ props: 'never', children: 'never', propElementValues: 'never' }],
954943
}
955944
)),
956945
});

0 commit comments

Comments
 (0)