Skip to content

Commit

Permalink
[fix] jsx-curly-brace-presence: allow necessary white-space literal
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Brown authored and ljharb committed Oct 2, 2019
1 parent d7d2a01 commit 4c89872
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/rules/jsx-curly-brace-presence.js
Expand Up @@ -238,7 +238,12 @@ module.exports = {

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

return adjSiblings.some(x => x.type && ['JSXExpressionContainer', 'JSXElement'].includes(x.type));
}
function shouldCheckForUnnecessaryCurly(parent, node, config) {
// Bail out if the parent is a JSXAttribute & its contents aren't
// StringLiteral or TemplateLiteral since e.g
Expand All @@ -259,7 +264,9 @@ module.exports = {
if (jsxUtil.isJSX(parent) && hasAdjacentJsxExpressionContainers(node, parent.children)) {
return false;
}

if (containsWhitespaceExpression(node) && hasAdjacentJsx(node, parent.children)) {
return false;
}
if (
parent.children &&
parent.children.length === 1 &&
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/jsx-curly-brace-presence.js
Expand Up @@ -85,6 +85,15 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
code: '<App>{`Hello ${word} World`}</App>',
options: [{children: 'never'}]
},
{
code: `
<>
foo{' '}
<span>bar</span>
</>
`,
options: [{children: 'never'}]
},
{
code: '<App>{`Hello \\n World`}</App>',
options: [{children: 'never'}]
Expand Down

0 comments on commit 4c89872

Please sign in to comment.