Skip to content

Commit

Permalink
Fix jsx-curly-spacing crash with ESLint 3 (fixes #1779)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed May 20, 2018
1 parent 0e9f1b1 commit b267d19
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/rules/jsx-curly-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,16 @@ module.exports = {
message: `There should be no space after '${token.value}'`,
fix: function(fixer) {
const nextToken = sourceCode.getTokenAfter(token);
const nextComment = sourceCode.getCommentsAfter(token);
let nextComment;

// ESLint >=4.x
if (sourceCode.getCommentsAfter) {
nextComment = sourceCode.getCommentsAfter(token);
// ESLint 3.x
} else {
const potentialComment = sourceCode.getTokenAfter(token, {includeComments: true});
nextComment = nextToken === potentialComment ? [] : [potentialComment];
}

// Take comments into consideration to narrow the fix range to what is actually affected. (See #1414)
if (nextComment.length > 0) {
Expand All @@ -253,7 +262,16 @@ module.exports = {
message: `There should be no space before '${token.value}'`,
fix: function(fixer) {
const previousToken = sourceCode.getTokenBefore(token);
const previousComment = sourceCode.getCommentsBefore(token);
let previousComment;

// ESLint >=4.x
if (sourceCode.getCommentsBefore) {
previousComment = sourceCode.getCommentsBefore(token);
// ESLint 3.x
} else {
const potentialComment = sourceCode.getTokenBefore(token, {includeComments: true});
previousComment = previousToken === potentialComment ? [] : [potentialComment];
}

// Take comments into consideration to narrow the fix range to what is actually affected. (See #1414)
if (previousComment.length > 0) {
Expand Down

0 comments on commit b267d19

Please sign in to comment.