Skip to content

Commit

Permalink
Update: fix no-dupe-keys false negatives on empty string names (#12069)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored and platinumazure committed Aug 18, 2019
1 parent 19ab666 commit 2dc23b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-dupe-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ module.exports = {
}

// Skip if the name is not static.
if (!name) {
if (name === null) {
return;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/no-dupe-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ ruleTester.run("no-dupe-keys", rule, {
valid: [
"var foo = { __proto__: 1, two: 2};",
"var x = { foo: 1, bar: 2 };",
"var x = { '': 1, bar: 2 };",
"var x = { '': 1, ' ': 2 };",
{ code: "var x = { '': 1, [null]: 2 };", parserOptions: { ecmaVersion: 6 } },
{ code: "var x = { '': 1, [a]: 2 };", parserOptions: { ecmaVersion: 6 } },
{ code: "var x = { [a]: 1, [a]: 2 };", parserOptions: { ecmaVersion: 6 } },
"+{ get a() { }, set a(b) { } };",
{ code: "var x = { a: b, [a]: b };", parserOptions: { ecmaVersion: 6 } },
{ code: "var x = { a: b, ...c }", parserOptions: { ecmaVersion: 2018 } },
Expand All @@ -32,6 +37,8 @@ ruleTester.run("no-dupe-keys", rule, {
invalid: [
{ code: "var x = { a: b, ['a']: b };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] },
{ code: "var x = { y: 1, y: 2 };", errors: [{ messageId: "unexpected", data: { name: "y" }, type: "ObjectExpression" }] },
{ code: "var x = { '': 1, '': 2 };", errors: [{ messageId: "unexpected", data: { name: "" }, type: "ObjectExpression" }] },
{ code: "var x = { '': 1, [``]: 2 };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "" }, type: "ObjectExpression" }] },
{ code: "var foo = { 0x1: 1, 1: 2};", errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] },
{ code: "var x = { \"z\": 1, z: 2 };", errors: [{ messageId: "unexpected", data: { name: "z" }, type: "ObjectExpression" }] },
{ code: "var foo = {\n bar: 1,\n bar: 1,\n}", errors: [{ messageId: "unexpected", data: { name: "bar" }, line: 3, column: 3 }] },
Expand Down

0 comments on commit 2dc23b8

Please sign in to comment.