Skip to content

Commit

Permalink
Fix: Ignore destructuring assignment in object-shorthand (fixes #5488)
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto committed Mar 6, 2016
1 parent 7051465 commit 9f18a81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/rules/object-shorthand.js
Expand Up @@ -50,6 +50,11 @@ module.exports = function(context) {
var isConciseProperty = node.method || node.shorthand,
type;

// Ignore destructuring assignment
if (node.parent.type === "ObjectPattern") {
return;
}

// if we're "never" and concise we should warn now
if (APPLY_NEVER && isConciseProperty) {
type = node.method ? "method" : "property";
Expand Down
5 changes: 4 additions & 1 deletion tests/lib/rules/object-shorthand.js
Expand Up @@ -79,7 +79,10 @@ ruleTester.run("object-shorthand", rule, {
{ code: "var x = {ConstructorFunction: function(){}, a: b}", parserOptions: { ecmaVersion: 6 }, options: ["methods", { "ignoreConstructors": true }] },
{ code: "var x = {notConstructorFunction(){}, b: c}", parserOptions: { ecmaVersion: 6 }, options: ["methods", { "ignoreConstructors": true }] },
{ code: "var x = {ConstructorFunction: function(){}, a: b}", parserOptions: { ecmaVersion: 6 }, options: ["never"] },
{ code: "var x = {notConstructorFunction: function(){}, b: c}", parserOptions: { ecmaVersion: 6 }, options: ["never"] }
{ code: "var x = {notConstructorFunction: function(){}, b: c}", parserOptions: { ecmaVersion: 6 }, options: ["never"] },

// ignore object shorthand
{ code: "let {a, b} = o;", parserOptions: { ecmaVersion: 6 }, options: ["never"] }
],
invalid: [
{ code: "var x = {x: x}", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Expected property shorthand.", type: "Property" }] },
Expand Down

0 comments on commit 9f18a81

Please sign in to comment.