Skip to content
Permalink
Browse files

Fix: Don't require commas after rest properties (fixes #7297) (#7298)

  • Loading branch information...
not-an-aardvark authored and nzakas committed Oct 10, 2016
1 parent 3b11d3f commit 52da71e9bfcdb7f13c6077531b992d059af7391a
Showing with 12 additions and 2 deletions.
  1. +5 −2 lib/rules/comma-dangle.js
  2. +7 −0 tests/lib/rules/comma-dangle.js
@@ -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"))
);
}

//------------------------------------------------------------------------------
@@ -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';",

0 comments on commit 52da71e

Please sign in to comment.
You can’t perform that action at this time.