Skip to content

Commit

Permalink
Fix: object-shorthand computed props (fixes #2937)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamund Ferguson committed Jul 7, 2015
1 parent b9fc9c5 commit 74dbc88
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/object-shorthand.js
Expand Up @@ -44,7 +44,8 @@ module.exports = function(context) {
return;
}

if (node.kind === "get" || node.kind === "set") {
// getters, setters and computed properties are ignored
if (node.kind === "get" || node.kind === "set" || node.computed) {
return;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/object-shorthand.js
Expand Up @@ -19,6 +19,7 @@ var eslint = require("../../../lib/eslint"),

var features = {
objectLiteralShorthandMethods: true,
objectLiteralComputedProperties: true,
objectLiteralShorthandProperties: true,
arrowFunctions: true,
destructuring: true,
Expand Down Expand Up @@ -68,6 +69,11 @@ eslintTester.addRuleTest("lib/rules/object-shorthand", {
{ code: "doSomething({set y(z) {}})", ecmaFeatures: features },
{ code: "doSomething({get y() {}, set y(z) {}})", ecmaFeatures: features },

// object literal computed properties
{ code: "var x = {[y]: y}", ecmaFeatures: features, args: [2, "properties"] },
{ code: "var x = {['y']: 'y'}", ecmaFeatures: features, args: [2, "properties"] },
{ code: "var x = {['y']: y}", ecmaFeatures: features, args: [2, "properties"] },

// options
{ code: "var x = {y() {}}", ecmaFeatures: features, args: [2, "methods"] },
{ code: "var x = {x, y() {}, a:b}", ecmaFeatures: features, args: [2, "methods"] },
Expand Down

0 comments on commit 74dbc88

Please sign in to comment.