6
6
7
7
'use strict' ;
8
8
9
+ const arrayIncludes = require ( 'array-includes' ) ;
10
+
9
11
const docsUrl = require ( '../util/docsUrl' ) ;
10
12
const jsxUtil = require ( '../util/jsx' ) ;
11
13
@@ -70,7 +72,7 @@ module.exports = {
70
72
}
71
73
72
74
function containsBackslash ( rawStringValue ) {
73
- return rawStringValue . includes ( '\\' ) ;
75
+ return arrayIncludes ( rawStringValue , '\\' ) ;
74
76
}
75
77
76
78
function containsHTMLEntity ( rawStringValue ) {
@@ -238,7 +240,12 @@ module.exports = {
238
240
239
241
return adjSiblings . some ( x => x . type && x . type === 'JSXExpressionContainer' ) ;
240
242
}
243
+ function hasAdjacentJsx ( node , children ) {
244
+ const childrenExcludingWhitespaceLiteral = children . filter ( child => ! isWhiteSpaceLiteral ( child ) ) ;
245
+ const adjSiblings = getAdjacentSiblings ( node , childrenExcludingWhitespaceLiteral ) ;
241
246
247
+ return adjSiblings . some ( x => x . type && arrayIncludes ( [ 'JSXExpressionContainer' , 'JSXElement' ] , x . type ) ) ;
248
+ }
242
249
function shouldCheckForUnnecessaryCurly ( parent , node , config ) {
243
250
// Bail out if the parent is a JSXAttribute & its contents aren't
244
251
// StringLiteral or TemplateLiteral since e.g
@@ -259,7 +266,9 @@ module.exports = {
259
266
if ( jsxUtil . isJSX ( parent ) && hasAdjacentJsxExpressionContainers ( node , parent . children ) ) {
260
267
return false ;
261
268
}
262
-
269
+ if ( containsWhitespaceExpression ( node ) && hasAdjacentJsx ( node , parent . children ) ) {
270
+ return false ;
271
+ }
263
272
if (
264
273
parent . children &&
265
274
parent . children . length === 1 &&
0 commit comments