diff --git a/lib/rules/arrow-parens.js b/lib/rules/arrow-parens.js index 60a043bb31b..d8ca0ecafb2 100644 --- a/lib/rules/arrow-parens.js +++ b/lib/rules/arrow-parens.js @@ -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); diff --git a/tests/lib/rules/arrow-parens.js b/tests/lib/rules/arrow-parens.js index a209d08c3eb..3fcd6fda606 100644 --- a/tests/lib/rules/arrow-parens.js +++ b/tests/lib/rules/arrow-parens.js @@ -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",