diff --git a/rules/string-content.js b/rules/string-content.js index f12607f4b0..646d6f696f 100644 --- a/rules/string-content.js +++ b/rules/string-content.js @@ -105,10 +105,13 @@ const create = context => { const fixed = string.replace(regex, suggest); const fix = type === 'Literal' - ? fixer => fixer.replaceText( - node, - escapeString(fixed, raw[0]), - ) + ? fixer => { + const [quote] = raw; + return fixer.replaceText( + node, + node.parent.type === 'JSXAttribute' ? quote + fixed + quote : escapeString(fixed, quote), + ); + } : fixer => replaceTemplateElement( fixer, node, diff --git a/test/string-content.mjs b/test/string-content.mjs index e8ca335909..c52f33fa0e 100644 --- a/test/string-content.mjs +++ b/test/string-content.mjs @@ -45,6 +45,13 @@ const createSuggestionError = (match, suggest, output) => [ ]; test({ + testerOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + }, + }, valid: [ 'const foo = "";', ...[ @@ -279,5 +286,19 @@ test({ errors: createError('no', 'yes'), }, /* eslint-enable no-template-curly-in-string */ + { + code: outdent` + const foo =
+ `, + output: outdent` + const foo =
+ `, + options: [{patterns: noToYesPattern}], + errors: createError('no', 'yes'), + }, ], });