Versions

no-dupe-keys

Disallow duplicate keys in object literals

Recommended

The "extends": "eslint:recommended" property in a configuration file enables this rule

在对象字面中具有相同键的多个属性会在你的应用程序中引起意外的行为。

var foo = {
    bar: "baz",
    bar: "qux"
};

规则细节

这条规则不允许在对象字面中出现重复的键。

使用此规则的错误示例:

Open in Playground
/*eslint no-dupe-keys: "error"*/

var foo = {
    bar: "baz",
    bar: "qux"
};

var foo = {
    "bar": "baz",
    bar: "qux"
};

var foo = {
    0x1: "baz",
    1: "qux"
};

使用此规则的正确示例:

Open in Playground
/*eslint no-dupe-keys: "error"*/

var foo = {
    bar: "baz",
    quxx: "qux"
};

Handled by TypeScript

It is safe to disable this rule when using TypeScript because TypeScript's compiler enforces this check.

Version

This rule was introduced in ESLint v0.0.9.

Resources

更改语言