Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
requireEnhancedObjectLiterals: Don't error for computed properties
Browse files Browse the repository at this point in the history
Fixes #2013
Closes gh-2058
  • Loading branch information
hzoo committed Jan 19, 2016
1 parent cc8a9e0 commit 168009d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/require-enhanced-object-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ module.exports.prototype = {
var propertyName = node.key.name || node.key.value;
var valueName = node.value.name;
var shorthand = node.shorthand;
var computed = node.computed;

// check for non-shorthand properties
if (propertyName && propertyName === valueName && !shorthand) {
if (propertyName && propertyName === valueName && !(shorthand || computed)) {
errors.add(
'Property assignment should use enhanced object literal function.\n' +
' `{ propName: propName }` is not allowed.',
Expand Down
7 changes: 7 additions & 0 deletions test/specs/rules/require-enhanced-object-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ describe('rules/require-enhanced-object-literals', function() {

expect(checker.checkString(code)).to.have.no.errors();
});

it('allows computed keys ', function() {
var checker = buildChecker({ requireEnhancedObjectLiterals: true });
var code = 'const COMMENTS = { [SINGLE_COMMENT]: SINGLE_COMMENT }';

expect(checker.checkString(code)).to.have.no.errors();
});
});

describe('when { requireEnhancedObjectLiterals: false }', function() {
Expand Down

0 comments on commit 168009d

Please sign in to comment.