When an object literal has the same key twice, the last value silently replaces the first. In a long object it's easy to add a key that's already there, and then one of the two has no effect.
A getter and a setter with the same name are a pair, so they're allowed.
This rule is on by default in JavaScript files. It's off in TypeScript files, where TypeScript reports the same mistake.
Configure
On by default as an error. To turn it off:
bunfig.toml
[lint.rules]
"no-dupe-keys" = "off" # or "warn"
Examples
Reported:
const options = {
timeout: 1000,
retries: 3,
timeout: 5000,
};
Not reported:
const options = {
timeout: 5000,
retries: 3,
};
Keys are compared by value, so "timeout" is the same key as timeout, and 0x1 is the same key as 1:
const options = {
timeout: 1000,
"timeout": 5000,
};
const labels = {
1: "one",
0x1: "uno",
};
A computed key such as [name] and a spread aren't compared, because their keys are only known at runtime:
const options = {
timeout: 1000,
[name]: 5000,
...overrides,
};