Skip to content

Commit b95e75e

Browse files
authoredNov 27, 2023
string-content: Fix JSX autofix for newlines, etc. (#2222)
1 parent f475168 commit b95e75e

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed
 

‎rules/string-content.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,13 @@ const create = context => {
105105

106106
const fixed = string.replace(regex, suggest);
107107
const fix = type === 'Literal'
108-
? fixer => fixer.replaceText(
109-
node,
110-
escapeString(fixed, raw[0]),
111-
)
108+
? fixer => {
109+
const [quote] = raw;
110+
return fixer.replaceText(
111+
node,
112+
node.parent.type === 'JSXAttribute' ? quote + fixed + quote : escapeString(fixed, quote),
113+
);
114+
}
112115
: fixer => replaceTemplateElement(
113116
fixer,
114117
node,

‎test/string-content.mjs

+21
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ const createSuggestionError = (match, suggest, output) => [
4545
];
4646

4747
test({
48+
testerOptions: {
49+
parserOptions: {
50+
ecmaFeatures: {
51+
jsx: true,
52+
},
53+
},
54+
},
4855
valid: [
4956
'const foo = "";',
5057
...[
@@ -279,5 +286,19 @@ test({
279286
errors: createError('no', 'yes'),
280287
},
281288
/* eslint-enable no-template-curly-in-string */
289+
{
290+
code: outdent`
291+
const foo = <div className='
292+
no
293+
' />
294+
`,
295+
output: outdent`
296+
const foo = <div className='
297+
yes
298+
' />
299+
`,
300+
options: [{patterns: noToYesPattern}],
301+
errors: createError('no', 'yes'),
302+
},
282303
],
283304
});

0 commit comments

Comments
 (0)
Please sign in to comment.