Skip to content

Commit

Permalink
Fix: comma-spacing ignore comma before closing paren (fixes #11295) (#…
Browse files Browse the repository at this point in the history
…11374)

* Fix: ignore comma before closing paren (fixes #11295)

* Chore: add more tests
  • Loading branch information
g-plane authored and btmills committed Feb 15, 2019
1 parent a1f7c44 commit e25e7aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/comma-spacing.js
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/comma-spacing.js
Expand Up @@ -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;'",
Expand Down

0 comments on commit e25e7aa

Please sign in to comment.