Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Aug 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rules/no-dupe-keys.js
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
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 } },
kaicataldo marked this conversation as resolved.
Show resolved Hide resolved
"+{ 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