Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: arrow-parens fixer gets tripped up with trailing comma in args (#…
  • Loading branch information
aladdin-add authored and gyandeeps committed Jun 29, 2017
1 parent c4f2e29 commit 5c3ac8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/rules/arrow-parens.js
Expand Up @@ -66,7 +66,10 @@ module.exports = {
*/
function fixParamsWithParenthesis(fixer) {
const paramToken = sourceCode.getTokenAfter(firstTokenOfParam);
const closingParenToken = sourceCode.getTokenAfter(paramToken);

// ES8 allows Trailing commas in function parameter lists and calls
// https://github.com/eslint/eslint/issues/8834
const closingParenToken = sourceCode.getTokenAfter(paramToken, astUtils.isClosingParenToken);
const asyncToken = isAsync ? sourceCode.getTokenBefore(firstTokenOfParam) : null;
const shouldAddSpaceForAsync = asyncToken && (asyncToken.end === firstTokenOfParam.start);

Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/arrow-parens.js
Expand Up @@ -164,6 +164,18 @@ const invalid = [
type
}]
},
{
code: "(a,) => a",
output: "a => a",
options: ["as-needed"],
parserOptions: { ecmaVersion: 8 },
errors: [{
line: 1,
column: 1,
message: asNeededMessage,
type
}]
},
{
code: "async (a) => a",
output: "async a => a",
Expand Down

0 comments on commit 5c3ac8e

Please sign in to comment.