Skip to content
Permalink
Browse files

Update: fix no-dupe-keys false negatives on empty string names (#12069)

  • Loading branch information
mdjermanovic authored and platinumazure committed Aug 18, 2019
1 parent 19ab666 commit 2dc23b81e54defbce7a70a7f26c2e4c7b692cf58
Showing with 8 additions and 1 deletion.
  1. +1 −1 lib/rules/no-dupe-keys.js
  2. +7 −0 tests/lib/rules/no-dupe-keys.js
@@ -120,7 +120,7 @@ module.exports = {
}

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

@@ -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 } },
@@ -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 }] },

0 comments on commit 2dc23b8

Please sign in to comment.
You can’t perform that action at this time.