Skip to content

Commit

Permalink
Revert "[Fix] jsx-curly-brace-presence: handle single and only expr…
Browse files Browse the repository at this point in the history
…ession template literals"

This reverts commit 099b14c / jsx-eslint#3538.

Fixes jsx-eslint#3607.
  • Loading branch information
taozhou-glean authored and ljharb committed Jul 23, 2023
1 parent 1a3a17a commit 698d6c7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

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

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

## [7.33.0] - 2023.07.19
Expand Down
10 changes: 0 additions & 10 deletions lib/rules/jsx-curly-brace-presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ module.exports = {
return containsLineTerminators(text) && text.trim() === '';
}

function isSingleExpressionTemplateLiteral(child) {
return child.type === 'TemplateLiteral' && child.expressions.length === 1 && child.quasis.map((quasis) => quasis.value.raw).join('') === '';
}

function wrapNonHTMLEntities(text) {
const HTML_ENTITY = '<HTML_ENTITY>';
const withCurlyBraces = text.split(HTML_ENTITY_REGEX()).map((word) => (
Expand Down Expand Up @@ -181,9 +177,6 @@ module.exports = {
if (jsxUtil.isJSX(expression)) {
const sourceCode = context.getSourceCode();
textToReplace = sourceCode.getText(expression);
} else if (isSingleExpressionTemplateLiteral(expression)) {
const sourceCode = context.getSourceCode();
textToReplace = `{${sourceCode.getText(expression.expressions[0])}}`;
} else {
const expressionType = expression && expression.type;
const parentType = JSXExpressionNode.parent.type;
Expand Down Expand Up @@ -286,9 +279,6 @@ module.exports = {
&& !containsQuoteCharacters(expression.quasis[0].value.cooked)
) {
reportUnnecessaryCurly(JSXExpressionNode);
} else if (
isSingleExpressionTemplateLiteral(expression)) {
reportUnnecessaryCurly(JSXExpressionNode);
} else if (jsxUtil.isJSX(expression)) {
reportUnnecessaryCurly(JSXExpressionNode);
}
Expand Down
45 changes: 17 additions & 28 deletions tests/lib/rules/jsx-curly-brace-presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,14 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
features: ['no-ts'],
options: ['never'],
},
// legit as this single template literal might be used for stringifying
{
code: '<App label={`${label}${suffix}`} />',
options: [{ props: 'never' }],
code: '<App label={`${label}`} />',
options: ['never'],
},
{
code: '<App>{`${label}${suffix}`}</App>',
options: [{ children: 'never' }],
code: '<App>{`${label}`}</App>',
options: ['never'],
}
)),

Expand Down Expand Up @@ -786,23 +787,23 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
},
{
code: `
<App prop="
a
<App prop="
a
b c
d
">
a
b c
d
b c
d
</App>
`,
errors: [
{ messageId: 'missingCurly' }, { messageId: 'missingCurly' },
],
options: ['always'],
output: `
<App prop="
a
<App prop="
a
b c
d
">
Expand All @@ -814,23 +815,23 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
},
{
code: `
<App prop='
a
<App prop='
a
b c
d
'>
a
b c
d
b c
d
</App>
`,
errors: [
{ messageId: 'missingCurly' }, { messageId: 'missingCurly' },
],
options: ['always'],
output: `
<App prop='
a
<App prop='
a
b c
d
'>
Expand Down Expand Up @@ -939,18 +940,6 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
errors: [{ messageId: 'unnecessaryCurly' }],
options: [{ props: 'never', children: 'never', propElementValues: 'never' }],
features: ['no-ts'],
},
{
code: '<App label={`${label}`} />',
output: '<App label={label} />',
errors: [{ messageId: 'unnecessaryCurly' }],
options: [{ props: 'never', children: 'never', propElementValues: 'never' }],
},
{
code: '<App>{`${label}`}</App>',
output: '<App>{label}</App>',
errors: [{ messageId: 'unnecessaryCurly' }],
options: [{ props: 'never', children: 'never', propElementValues: 'never' }],
}
)),
});

0 comments on commit 698d6c7

Please sign in to comment.