Skip to content

Commit

Permalink
Fix: comma-style autofix produces errors on parenthesized elements (#…
Browse files Browse the repository at this point in the history
…8331)

Previously, the autofixer would produce invalid syntax if it encountered a parenthesized element followed by a missing element on the next line. This commit updates the token logic to avoid that error.
  • Loading branch information
not-an-aardvark committed Mar 28, 2017
1 parent d52173f commit a9d1bea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rules/comma-style.js
Expand Up @@ -205,7 +205,11 @@ module.exports = {
currentItemToken, reportItem);
}

previousItemToken = item ? sourceCode.getLastToken(item) : previousItemToken;
if (item) {
const tokenAfterItem = sourceCode.getTokenAfter(item, astUtils.isNotClosingParenToken);

previousItemToken = tokenAfterItem ? sourceCode.getTokenBefore(tokenAfterItem) : sourceCode.ast.tokens[sourceCode.ast.tokens.length - 1];
}
});

/*
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/comma-style.js
Expand Up @@ -569,6 +569,11 @@ ruleTester.run("comma-style", rule, {
message: BAD_LN_BRK_MSG,
type: "Identifier"
}]
},
{
code: "[(foo),\n,\nbar]",
output: "[(foo),,\nbar]",
errors: [{ message: BAD_LN_BRK_MSG }]
}
]
});

0 comments on commit a9d1bea

Please sign in to comment.