Skip to content

Commit

Permalink
Fix: object-shorthand should only lint computed methods (fixes #6015) (
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo authored and nzakas committed May 3, 2016
1 parent cd1b057 commit ef8cbff
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/rules/object-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module.exports = {
}

// only computed methods can fail the following checks
if (!APPLY_TO_METHODS && node.computed) {
if (node.computed && node.value.type !== "FunctionExpression") {
return;
}

Expand All @@ -136,6 +136,5 @@ module.exports = {
}
}
};

}
};
2 changes: 2 additions & 0 deletions tests/lib/rules/object-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ruleTester.run("object-shorthand", rule, {
{ code: "var x = {x: y, y: z, a: b}", parserOptions: { ecmaVersion: 6 }},
{ code: "var x = {x: y, y: z, 'a': b}", parserOptions: { ecmaVersion: 6 }},
{ code: "var x = {x: y, y() {}, z: a}", parserOptions: { ecmaVersion: 6 }},
{ code: "var x = {[y]: y}", parserOptions: { ecmaVersion: 6 }},
{ code: "doSomething({x: y})", parserOptions: { ecmaVersion: 6 }},
{ code: "doSomething({'x': y})", parserOptions: { ecmaVersion: 6 }},
{ code: "doSomething({x: 'x'})", parserOptions: { ecmaVersion: 6 }},
Expand Down Expand Up @@ -68,6 +69,7 @@ ruleTester.run("object-shorthand", rule, {
// object literal computed methods
{ code: "var x = {[y]() {}}", parserOptions: { ecmaVersion: 6 }, options: ["methods"] },
{ code: "var x = {[y]: function x() {}}", parserOptions: { ecmaVersion: 6 }, options: ["methods"] },
{ code: "var x = {[y]: y}", parserOptions: { ecmaVersion: 6 }, options: ["methods"] },

// options
{ code: "var x = {y() {}}", parserOptions: { ecmaVersion: 6 }, options: ["methods"] },
Expand Down

0 comments on commit ef8cbff

Please sign in to comment.