Skip to content

Commit

Permalink
Fix: Don't require commas after rest properties (fixes #7297) (#7298)
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark authored and nzakas committed Oct 10, 2016
1 parent 3b11d3f commit 52da71e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/rules/comma-dangle.js
Expand Up @@ -13,14 +13,17 @@ const lodash = require("lodash");

/**
* Checks whether or not a trailing comma is allowed in a given node.
* `ArrayPattern` which has `RestElement` disallows it.
* `ArrayPattern` which has `RestElement` or `ObjectPattern` which has `RestProperty` disallows it.
*
* @param {ASTNode} node - A node to check.
* @param {ASTNode} lastItem - The node of the last element in the given node.
* @returns {boolean} `true` if a trailing comma is allowed.
*/
function isTrailingCommaAllowed(node, lastItem) {
return node.type !== "ArrayPattern" || lastItem.type !== "RestElement";
return !(
(node.type === "ArrayPattern" && lastItem.type === "RestElement") ||
(node.type === "ObjectPattern" && (lastItem.type === "RestProperty" || lastItem.type === "ExperimentalRestProperty"))
);
}

//------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/comma-dangle.js
Expand Up @@ -116,6 +116,13 @@ ruleTester.run("comma-dangle", rule, {
options: ["always"]
},

// https://github.com/eslint/eslint/issues/7297
{
code: "var {foo, ...bar} = baz",
parserOptions: { ecmaVersion: 8, ecmaFeatures: { experimentalObjectRestSpread: true } },
options: ["always"]
},

// https://github.com/eslint/eslint/issues/3794
{
code: "import {foo,} from 'foo';",
Expand Down

0 comments on commit 52da71e

Please sign in to comment.