no-dupe-keys
NOTE: this rule is part of the
推荐 rule set.Enable full set in
deno.json:{
"lint": {
"rules": {
"tags": ["推荐"]
}
}
}Enable full set using the Deno CLI:
deno lint --rules-tags=推荐
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the
include or exclude array in deno.json:{
"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",
};