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

Commit 168009d

Browse files
committed
requireEnhancedObjectLiterals: Don't error for computed properties
Fixes #2013 Closes gh-2058
1 parent cc8a9e0 commit 168009d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/rules/require-enhanced-object-literals.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ module.exports.prototype = {
5454
var propertyName = node.key.name || node.key.value;
5555
var valueName = node.value.name;
5656
var shorthand = node.shorthand;
57+
var computed = node.computed;
5758

5859
// check for non-shorthand properties
59-
if (propertyName && propertyName === valueName && !shorthand) {
60+
if (propertyName && propertyName === valueName && !(shorthand || computed)) {
6061
errors.add(
6162
'Property assignment should use enhanced object literal function.\n' +
6263
' `{ propName: propName }` is not allowed.',

test/specs/rules/require-enhanced-object-literals.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ describe('rules/require-enhanced-object-literals', function() {
3232

3333
expect(checker.checkString(code)).to.have.no.errors();
3434
});
35+
36+
it('allows computed keys ', function() {
37+
var checker = buildChecker({ requireEnhancedObjectLiterals: true });
38+
var code = 'const COMMENTS = { [SINGLE_COMMENT]: SINGLE_COMMENT }';
39+
40+
expect(checker.checkString(code)).to.have.no.errors();
41+
});
3542
});
3643

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

0 commit comments

Comments
 (0)