Skip to content

Commit 9219e52

Browse files
committed
[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 36a2008 commit 9219e52

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
@@ -226,6 +226,13 @@ module.exports = {
226226
message: `There should be no space after '${token.value}'`,
227227
fix: function(fixer) {
228228
const nextToken = sourceCode.getTokenAfter(token);
229+
const nextComment = sourceCode.getCommentsAfter(token);
230+
231+
// Take comments into consideration to narrow the fix range to what is actually affected. (See #1414)
232+
if (nextComment.length > 0) {
233+
return fixByTrimmingWhitespace(fixer, token.range[1], Math.min(nextToken.range[0], nextComment[0].start), 'start');
234+
}
235+
229236
return fixByTrimmingWhitespace(fixer, token.range[1], nextToken.range[0], 'start');
230237
}
231238
});
@@ -244,6 +251,13 @@ module.exports = {
244251
message: `There should be no space before '${token.value}'`,
245252
fix: function(fixer) {
246253
const previousToken = sourceCode.getTokenBefore(token);
254+
const previousComment = sourceCode.getCommentsBefore(token);
255+
256+
// Take comments into consideration to narrow the fix range to what is actually affected. (See #1414)
257+
if (previousComment.length > 0) {
258+
return fixByTrimmingWhitespace(fixer, Math.max(previousToken.range[1], previousComment[0].end), token.range[0], 'end');
259+
}
260+
247261
return fixByTrimmingWhitespace(fixer, previousToken.range[1], token.range[0], 'end');
248262
}
249263
});

0 commit comments

Comments
 (0)