Skip to content

Commit 4c89872

Browse files
Cory Brownljharb
Cory Brown
authored andcommitted
[fix] jsx-curly-brace-presence: allow necessary white-space literal
1 parent d7d2a01 commit 4c89872

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ module.exports = {
238238

239239
return adjSiblings.some(x => x.type && x.type === 'JSXExpressionContainer');
240240
}
241+
function hasAdjacentJsx(node, children) {
242+
const childrenExcludingWhitespaceLiteral = children.filter(child => !isWhiteSpaceLiteral(child));
243+
const adjSiblings = getAdjacentSiblings(node, childrenExcludingWhitespaceLiteral);
241244

245+
return adjSiblings.some(x => x.type && ['JSXExpressionContainer', 'JSXElement'].includes(x.type));
246+
}
242247
function shouldCheckForUnnecessaryCurly(parent, node, config) {
243248
// Bail out if the parent is a JSXAttribute & its contents aren't
244249
// StringLiteral or TemplateLiteral since e.g
@@ -259,7 +264,9 @@ module.exports = {
259264
if (jsxUtil.isJSX(parent) && hasAdjacentJsxExpressionContainers(node, parent.children)) {
260265
return false;
261266
}
262-
267+
if (containsWhitespaceExpression(node) && hasAdjacentJsx(node, parent.children)) {
268+
return false;
269+
}
263270
if (
264271
parent.children &&
265272
parent.children.length === 1 &&

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
8585
code: '<App>{`Hello ${word} World`}</App>',
8686
options: [{children: 'never'}]
8787
},
88+
{
89+
code: `
90+
<>
91+
foo{' '}
92+
<span>bar</span>
93+
</>
94+
`,
95+
options: [{children: 'never'}]
96+
},
8897
{
8998
code: '<App>{`Hello \\n World`}</App>',
9099
options: [{children: 'never'}]

0 commit comments

Comments
 (0)