禁止重复键
注意:此规则是
推荐规则集的一部分。在
deno.json 中启用完整集合{
"lint": {
"rules": {
"tags": ["recommended"]
}
}
}使用 Deno CLI 启用完整集合
deno lint --rules-tags=recommended
通过将其添加到
deno.json 中的 include 或 exclude 数组,可以将此规则明确地包含或排除在当前标签中的规则之外。{
"lint": {
"rules": {
"include": ["no-dupe-keys"],
"exclude": ["no-dupe-keys"]
}
}
}禁止对象字面量中的重复键。
在对象字面量中多次设置同一个键将覆盖对该键的其他赋值,并可能导致意外行为。
无效示例
const foo = {
bar: "baz",
bar: "qux",
};
const foo = {
"bar": "baz",
bar: "qux",
};
const foo = {
0x1: "baz",
1: "qux",
};
有效示例
const foo = {
bar: "baz",
quxx: "qux",
};