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 59d65dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
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
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
23 changes: 7 additions & 16 deletions tests/lib/rules/jsx-curly-brace-presence.js
Expand Up @@ -469,13 +469,16 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
features: ['no-ts'],
options: ['never'],
},
// legit as this single template literal might be used for type casting
{
code: '<App label={`${label}${suffix}`} />',
options: [{ props: 'never' }],
code: '<App label={`${label}`} />',
output: '<App label={label} />',
options: ['never'],
},
{
code: '<App>{`${label}${suffix}`}</App>',
options: [{ children: 'never' }],
code: '<App>{`${label}`}</App>',
output: '<App>{label}</App>',
options: ['never'],
}
)),

Expand Down Expand Up @@ -939,18 +942,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 59d65dd

Please sign in to comment.