From 59d65ddc90942f917d6de3e21287b43a07682dbb Mon Sep 17 00:00:00 2001 From: Tao Zhou Date: Sun, 23 Jul 2023 07:10:14 -0700 Subject: [PATCH] Revert "[Fix] `jsx-curly-brace-presence`: handle single and only expression template literals" This reverts commit 099b14caef4dc5ed496a5ae66d1b07b3b5c8741d / #3538. Fixes #3607. --- CHANGELOG.md | 2 ++ lib/rules/jsx-curly-brace-presence.js | 10 --------- tests/lib/rules/jsx-curly-brace-presence.js | 23 +++++++-------------- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8b95aa600..ba18b5def3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rules/jsx-curly-brace-presence.js b/lib/rules/jsx-curly-brace-presence.js index 28b72e86eb..c7b3e55d2e 100755 --- a/lib/rules/jsx-curly-brace-presence.js +++ b/lib/rules/jsx-curly-brace-presence.js @@ -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 = ''; const withCurlyBraces = text.split(HTML_ENTITY_REGEX()).map((word) => ( @@ -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; @@ -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); } diff --git a/tests/lib/rules/jsx-curly-brace-presence.js b/tests/lib/rules/jsx-curly-brace-presence.js index 284d008bfd..609a23fb6f 100755 --- a/tests/lib/rules/jsx-curly-brace-presence.js +++ b/tests/lib/rules/jsx-curly-brace-presence.js @@ -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: '', - options: [{ props: 'never' }], + code: '', + output: '', + options: ['never'], }, { - code: '{`${label}${suffix}`}', - options: [{ children: 'never' }], + code: '{`${label}`}', + output: '{label}', + options: ['never'], } )), @@ -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: '', - output: '', - errors: [{ messageId: 'unnecessaryCurly' }], - options: [{ props: 'never', children: 'never', propElementValues: 'never' }], - }, - { - code: '{`${label}`}', - output: '{label}', - errors: [{ messageId: 'unnecessaryCurly' }], - options: [{ props: 'never', children: 'never', propElementValues: 'never' }], } )), });