Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] jsx-curly-brace-presence warns incorrectly on trailing whitespace #2431

Merged
merged 1 commit into from Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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