Skip to content

Commit

Permalink
Fix: line number for duplicate object keys error (fixes #3573)
Browse files Browse the repository at this point in the history
  • Loading branch information
Elliot Lynde committed Aug 29, 2015
1 parent 917e37f commit 01b0d65
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/no-dupe-keys.js
Expand Up @@ -33,7 +33,7 @@ module.exports = function(context) {

if (checkProperty) {
if (nodeProps[key]) {
context.report(node, "Duplicate key '{{key}}'.", { key: keyName });
context.report(node, property.loc.start, "Duplicate key '{{key}}'.", { key: keyName });
} else {
nodeProps[key] = true;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/rules/no-dupe-keys.js
Expand Up @@ -31,6 +31,7 @@ ruleTester.run("no-dupe-keys", rule, {
{ code: "var x = { a: b, ['a']: b };", ecmaFeatures: { objectLiteralComputedProperties: true }, errors: [{ message: "Duplicate key 'a'.", type: "ObjectExpression"}] },
{ code: "var x = { y: 1, y: 2 };", errors: [{ message: "Duplicate key 'y'.", type: "ObjectExpression"}] },
{ code: "var foo = { 0x1: 1, 1: 2};", errors: [{ message: "Duplicate key '1'.", type: "ObjectExpression"}] },
{ code: "var x = { \"z\": 1, z: 2 };", errors: [{ message: "Duplicate key 'z'.", type: "ObjectExpression"}] }
{ code: "var x = { \"z\": 1, z: 2 };", errors: [{ message: "Duplicate key 'z'.", type: "ObjectExpression"}] },
{ code: "var foo = {\n bar: 1,\n bar: 1,\n}", errors: [{ message: "Duplicate key 'bar'.", line: 3, column: 3}]}
]
});

0 comments on commit 01b0d65

Please sign in to comment.