From e25e7aa3ea1e8c9b3cd3242acda6d4a5572c2c6a Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sat, 16 Feb 2019 03:54:33 +0800 Subject: [PATCH] Fix: comma-spacing ignore comma before closing paren (fixes #11295) (#11374) * Fix: ignore comma before closing paren (fixes #11295) * Chore: add more tests --- lib/rules/comma-spacing.js | 4 ++++ tests/lib/rules/comma-spacing.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/rules/comma-spacing.js b/lib/rules/comma-spacing.js index 789de7843c3..a9f89676a4a 100644 --- a/lib/rules/comma-spacing.js +++ b/lib/rules/comma-spacing.js @@ -120,6 +120,10 @@ module.exports = { report(reportItem, "before", tokens.left); } + if (tokens.right && astUtils.isClosingParenToken(tokens.right)) { + return; + } + if (tokens.right && !options.after && tokens.right.type === "Line") { return; } diff --git a/tests/lib/rules/comma-spacing.js b/tests/lib/rules/comma-spacing.js index d5c8ff0ec84..2df7c71fadc 100644 --- a/tests/lib/rules/comma-spacing.js +++ b/tests/lib/rules/comma-spacing.js @@ -61,6 +61,10 @@ ruleTester.run("comma-spacing", rule, { "[' , ']", { code: "[` , `]", parserOptions: { ecmaVersion: 6 } }, { code: "`${[1, 2]}`", parserOptions: { ecmaVersion: 6 } }, + { code: "fn(a, b,)", parserOptions: { ecmaVersion: 2018 } }, // #11295 + { code: "const fn = (a, b,) => {}", parserOptions: { ecmaVersion: 2018 } }, // #11295 + { code: "const fn = function (a, b,) {}", parserOptions: { ecmaVersion: 2018 } }, // #11295 + { code: "function fn(a, b,) {}", parserOptions: { ecmaVersion: 2018 } }, // #11295 "foo(/,/, 'a')", "var x = ',,,,,';", "var code = 'var foo = 1, bar = 3;'",