Skip to content

Commit 8751e92

Browse files
committed
Bail out for line-breakers in JSX
1 parent dc523b1 commit 8751e92

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

lib/rules/jsx-curly-brace-presence.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ module.exports = {
5959
{props: ruleOptions, children: ruleOptions} :
6060
Object.assign({}, DEFAULT_CONFIG, ruleOptions);
6161

62+
function containsLineTerminators(rawStringValue) {
63+
return /[\n\r\u2028\u2029]+/.test(rawStringValue);
64+
}
65+
6266
function containsBackslash(rawStringValue) {
6367
return rawStringValue.includes('\\');
6468
}
@@ -125,9 +129,13 @@ module.exports = {
125129
node: literalNode,
126130
message: 'Need to wrap this literal in a JSX expression.',
127131
fix: function(fixer) {
128-
// Leave it to the author to fix as it can be fixed by either a
129-
// real character or unicode
130-
if (containsHTMLEntity(literalNode.raw)) {
132+
// If a HTML entity name is found, bail out because it can be fixed
133+
// by either using the real character or the unicode equivalent.
134+
// If it contains any line terminator character, bail out as well.
135+
if (
136+
containsHTMLEntity(literalNode.raw) ||
137+
containsLineTerminators(literalNode.raw)
138+
) {
131139
return null;
132140
}
133141

tests/lib/rules/jsx-curly-brace-presence.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,6 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
411411
' d ',
412412
'</App>'
413413
].join('\n'),
414-
output: [
415-
'<App prop={" ',
416-
' a ',
417-
' b c',
418-
' d',
419-
'"}>{"\\n a\\n b c \\n d \\n"}</App>'
420-
].join('\n'),
421414
errors: [
422415
{message: missingCurlyMessage}, {message: missingCurlyMessage}
423416
],
@@ -435,13 +428,6 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
435428
' d ',
436429
'</App>'
437430
].join('\n'),
438-
output: [
439-
'<App prop={" ',
440-
' a ',
441-
' b c',
442-
' d',
443-
'"}>{"\\n a\\n b c \\n d \\n"}</App>'
444-
].join('\n'),
445431
errors: [
446432
{message: missingCurlyMessage}, {message: missingCurlyMessage}
447433
],

0 commit comments

Comments
 (0)