版本

no-dupe-keys

禁止对象字面量中的重复键

推荐

配置文件中使用来自@eslint/jsrecommended配置启用此规则

对象字面量中具有相同键的多个属性可能会导致应用程序中出现意外行为。

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

规则详情

此规则禁止对象字面量中的重复键。

此规则的错误代码示例

在 Playground 中打开
/*eslint no-dupe-keys: "error"*/

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

const bar = {
    "bar": "baz",
    bar: "qux"
};

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

此规则的正确代码示例

在 Playground 中打开
/*eslint no-dupe-keys: "error"*/

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

由 TypeScript 处理

当使用 TypeScript 时,禁用此规则是安全的,因为 TypeScript 的编译器会强制执行此检查。

版本

此规则在 ESLint v0.0.9 中引入。

资源

更改语言