Skip to content

Commit

Permalink
[Fix] jsx-curly-brace-presence: warns incorrectly on trailing white…
Browse files Browse the repository at this point in the history
…space

Fixes #2427
  • Loading branch information
bc-m authored and ljharb committed Oct 2, 2019
1 parent c153a86 commit d7d2a01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/rules/jsx-curly-brace-presence.js
Expand Up @@ -168,6 +168,10 @@ module.exports = {
});
}

function isWhiteSpaceLiteral(node) {
return node.type && node.type === 'Literal' && node.value && jsxUtil.isWhiteSpaces(node.value);
}

// Bail out if there is any character that needs to be escaped in JSX
// because escaping decreases readiblity and the original code may be more
// readible anyway or intentional for other specific reasons
Expand All @@ -178,6 +182,7 @@ module.exports = {
if (
(expressionType === 'Literal' || expressionType === 'JSXText') &&
typeof expression.value === 'string' &&
!isWhiteSpaceLiteral(expression) &&
!needToEscapeCharacterForJSX(expression.raw) && (
jsxUtil.isJSX(JSXExpressionNode.parent) ||
!containsQuoteCharacters(expression.value)
Expand Down Expand Up @@ -211,10 +216,6 @@ module.exports = {
);
}

function isWhiteSpaceLiteral(node) {
return node.type && node.type === 'Literal' && node.value && jsxUtil.isWhiteSpaces(node.value);
}

function getAdjacentSiblings(node, children) {
for (let i = 1; i < children.length - 1; i++) {
const child = children[i];
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/jsx-curly-brace-presence.js
Expand Up @@ -52,9 +52,15 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
{
code: '<App>{\' \'}</App>'
},
{
code: '<App>{\' \'}\n</App>'
},
{
code: '<App>{\' \'}</App>'
},
{
code: '<App>{\' \'}\n</App>'
},
{
code: '<App>{\' \'}</App>',
options: [{children: 'never'}]
Expand Down

0 comments on commit d7d2a01

Please sign in to comment.