From cbae656ab6540804d45cd7392a2f6d5a647ba52b Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Mon, 11 Feb 2019 09:25:51 +0800 Subject: [PATCH 1/2] Fix: ignore comma before closing paren (fixes #11295) --- lib/rules/comma-spacing.js | 4 ++++ tests/lib/rules/comma-spacing.js | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/rules/comma-spacing.js b/lib/rules/comma-spacing.js index 2db0035b545..1d1cf2e59b5 100644 --- a/lib/rules/comma-spacing.js +++ b/lib/rules/comma-spacing.js @@ -118,6 +118,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..8cdf7e08014 100644 --- a/tests/lib/rules/comma-spacing.js +++ b/tests/lib/rules/comma-spacing.js @@ -61,6 +61,7 @@ ruleTester.run("comma-spacing", rule, { "[' , ']", { code: "[` , `]", parserOptions: { ecmaVersion: 6 } }, { code: "`${[1, 2]}`", parserOptions: { ecmaVersion: 6 } }, + { code: "fn(a, b,)", parserOptions: { ecmaVersion: 2018 } }, // #11295 "foo(/,/, 'a')", "var x = ',,,,,';", "var code = 'var foo = 1, bar = 3;'", From 386ade645d2e7e786d94d3f1e1780039ace202c3 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Thu, 14 Feb 2019 09:14:42 +0800 Subject: [PATCH 2/2] Chore: add more tests --- tests/lib/rules/comma-spacing.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/lib/rules/comma-spacing.js b/tests/lib/rules/comma-spacing.js index 8cdf7e08014..2df7c71fadc 100644 --- a/tests/lib/rules/comma-spacing.js +++ b/tests/lib/rules/comma-spacing.js @@ -62,6 +62,9 @@ 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;'",