noDuplicateEnumValues
Summary
Section titled “Summary”- Rule available since:
v2.3.12 - Diagnostic Category:
lint/suspicious/noDuplicateEnumValues - This rule is recommended, meaning it is enabled by default.
- This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "suspicious": { "noDuplicateEnumValues": "error" } } }}Description
Section titled “Description”Disallow duplicate enum member values.
Although TypeScript supports duplicate enum member values, people usually expect members to have unique values within the same enum. Duplicate values can lead to bugs that are hard to track down.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”enum E { A = 0, B = 0,}code-block.ts:3:3 lint/suspicious/noDuplicateEnumValues ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Duplicate enum member value.
1 │ enum E {
2 │ A = 0,
> 3 │ B = 0,
│ ^^^^^
4 │ }
5 │
ℹ Expected members to have unique values. Duplicate values can lead to bugs that are hard to track down.
enum E { A = "A", B = 'A', C = `A`,}code-block.ts:3:3 lint/suspicious/noDuplicateEnumValues ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Duplicate enum member value.
1 │ enum E {
2 │ A = “A”,
> 3 │ B = ‘A’,
│ ^^^^^^^
4 │ C = `A`,
5 │ }
ℹ Another duplicate enum member value.
2 │ A = “A”,
3 │ B = ‘A’,
> 4 │ C = `A`,
│ ^^^^^^^
5 │ }
6 │
ℹ Expected members to have unique values. Duplicate values can lead to bugs that are hard to track down.
enum E { A = 0, B = 1,}enum E { A = "A", B = 'B', C = `C`,}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.