From 10eb2350a42e4645f33a594f63e74fc3aceef939 Mon Sep 17 00:00:00 2001 From: akulsr0 Date: Thu, 8 Aug 2024 19:34:10 +0530 Subject: [PATCH] [Fix] `jsx-curly-brace-presence`: do not trigger on strings containing a quote character --- CHANGELOG.md | 5 +++++ lib/rules/jsx-curly-brace-presence.js | 2 +- tests/lib/rules/jsx-curly-brace-presence.js | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6aca8c45b..98edcee215 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ## Unreleased +### Fixed +* [`jsx-curly-brace-presence`]: do not trigger on strings containing a quote character ([#3798][] @akulsr0) + +[#3798]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3798 + ## [7.35.0] - 2024.07.19 ### Added diff --git a/lib/rules/jsx-curly-brace-presence.js b/lib/rules/jsx-curly-brace-presence.js index 213e0ce3ca..cfbe3bda8d 100755 --- a/lib/rules/jsx-curly-brace-presence.js +++ b/lib/rules/jsx-curly-brace-presence.js @@ -269,7 +269,7 @@ module.exports = { && !containsMultilineComment(expression.value) && !needToEscapeCharacterForJSX(expression.raw, JSXExpressionNode) && ( jsxUtil.isJSX(JSXExpressionNode.parent) - || !containsQuoteCharacters(expression.value) + || (!containsQuoteCharacters(expression.value) || typeof expression.value === 'string') ) ) { reportUnnecessaryCurly(JSXExpressionNode); diff --git a/tests/lib/rules/jsx-curly-brace-presence.js b/tests/lib/rules/jsx-curly-brace-presence.js index 4c157deb0c..259b9538b2 100755 --- a/tests/lib/rules/jsx-curly-brace-presence.js +++ b/tests/lib/rules/jsx-curly-brace-presence.js @@ -934,6 +934,12 @@ 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' }], } )), });