Skip to content

Commit e4de360

Browse files
s-h-a-d-o-wljharb
authored andcommitted
[Fix] jsx-curly-spacing problem in new tests, fixes #1414
Before this, spaces before/after braces when there should be none resulted in two overlapping fixes for the full brace content. And so they required two passes. But the tester does only one pass, so only one white space was fixed and the test failed. By including comments in the range calculation for the fix, the range is now properly limited, making it possible to have start and end fixes in one pass.
1 parent a2764d9 commit e4de360

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/rules/jsx-curly-spacing.js

+14
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ module.exports = {
228228
message: `There should be no space after '${token.value}'`,
229229
fix: function(fixer) {
230230
const nextToken = sourceCode.getTokenAfter(token);
231+
const nextComment = sourceCode.getCommentsAfter(token);
232+
233+
// Take comments into consideration to narrow the fix range to what is actually affected. (See #1414)
234+
if (nextComment.length > 0) {
235+
return fixByTrimmingWhitespace(fixer, token.range[1], Math.min(nextToken.range[0], nextComment[0].start), 'start');
236+
}
237+
231238
return fixByTrimmingWhitespace(fixer, token.range[1], nextToken.range[0], 'start');
232239
}
233240
});
@@ -246,6 +253,13 @@ module.exports = {
246253
message: `There should be no space before '${token.value}'`,
247254
fix: function(fixer) {
248255
const previousToken = sourceCode.getTokenBefore(token);
256+
const previousComment = sourceCode.getCommentsBefore(token);
257+
258+
// Take comments into consideration to narrow the fix range to what is actually affected. (See #1414)
259+
if (previousComment.length > 0) {
260+
return fixByTrimmingWhitespace(fixer, Math.max(previousToken.range[1], previousComment[0].end), token.range[0], 'end');
261+
}
262+
249263
return fixByTrimmingWhitespace(fixer, previousToken.range[1], token.range[0], 'end');
250264
}
251265
});

0 commit comments

Comments
 (0)