Skip to content

Commit d7d2a01

Browse files
bc-mljharb
authored andcommitted
[Fix] jsx-curly-brace-presence: warns incorrectly on trailing whitespace
Fixes #2427
1 parent c153a86 commit d7d2a01

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ module.exports = {
168168
});
169169
}
170170

171+
function isWhiteSpaceLiteral(node) {
172+
return node.type && node.type === 'Literal' && node.value && jsxUtil.isWhiteSpaces(node.value);
173+
}
174+
171175
// Bail out if there is any character that needs to be escaped in JSX
172176
// because escaping decreases readiblity and the original code may be more
173177
// readible anyway or intentional for other specific reasons
@@ -178,6 +182,7 @@ module.exports = {
178182
if (
179183
(expressionType === 'Literal' || expressionType === 'JSXText') &&
180184
typeof expression.value === 'string' &&
185+
!isWhiteSpaceLiteral(expression) &&
181186
!needToEscapeCharacterForJSX(expression.raw) && (
182187
jsxUtil.isJSX(JSXExpressionNode.parent) ||
183188
!containsQuoteCharacters(expression.value)
@@ -211,10 +216,6 @@ module.exports = {
211216
);
212217
}
213218

214-
function isWhiteSpaceLiteral(node) {
215-
return node.type && node.type === 'Literal' && node.value && jsxUtil.isWhiteSpaces(node.value);
216-
}
217-
218219
function getAdjacentSiblings(node, children) {
219220
for (let i = 1; i < children.length - 1; i++) {
220221
const child = children[i];

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,15 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
5252
{
5353
code: '<App>{\' \'}</App>'
5454
},
55+
{
56+
code: '<App>{\' \'}\n</App>'
57+
},
5558
{
5659
code: '<App>{\' \'}</App>'
5760
},
61+
{
62+
code: '<App>{\' \'}\n</App>'
63+
},
5864
{
5965
code: '<App>{\' \'}</App>',
6066
options: [{children: 'never'}]

0 commit comments

Comments
 (0)