{"record":{"id":"6ecfe33fce8fce05","repo":"oxc-project/oxc","slug":"duplicate-enum-value-value","errorCode":null,"errorMessage":"Duplicate enum value `{value}`","messagePattern":"Duplicate enum value `(.+?)`","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/no_duplicate_enum_values.rs","lineNumber":26,"sourceCode":"use rustc_hash::FxHashMap;\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::Rule,\n};\n\nfn no_duplicate_enum_values_diagnostic(\n    first_init_span: Span,\n    second_member: &TSEnumMember,\n    value: &str,\n) -> OxcDiagnostic {\n    let second_name = second_member.id.static_name();\n    // Unwrap will never panic since violations are only reported for members\n    // with initializers.\n    let second_init_span = second_member.initializer.as_ref().map(GetSpan::span).unwrap();\n\n    OxcDiagnostic::warn(format!(\"Duplicate enum value `{value}`\"))\n        .with_help(format!(\"Give {second_name} a unique value\"))\n        .with_labels([\n            first_init_span.label(format!(\"{value} is first used as an initializer here\")),\n            second_init_span.label(\"and is re-used here\"),\n        ])\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoDuplicateEnumValues;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow duplicate enum member values.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Although TypeScript supports duplicate enum member values, people","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/no_duplicate_enum_values.rs#L8-L44","documentation":"typescript/no-duplicate-enum-values reports enum members whose initializer value was already used by an earlier member in the same enum. TypeScript allows duplicate values (only names must be unique), but they are usually mistakes, and for string enums they make the reverse mapping ambiguous for tooling. The diagnostic carries two labels: where the value was first used and where it is re-used.","triggerScenarios":"`enum E { A = 1, B = 1 }`, `enum Flags { X = 1 << 0, Y = 1, Z = 1 }`, or computed initializers that evaluate to the same value; the rule tracks values via static evaluation of member initializers and reports the second member with both initializer spans labeled.","commonSituations":"Copy-pasting enum members and forgetting to bump the value; bitwise-flag enums where two members get the same bit; refactors converting string enums to numeric ones; accidental collisions after inserting a member with an explicit value.","solutions":["Give the duplicate member a unique value: `enum E { A = 1, B = 2 }`","If the collision is intentional aliasing, name it clearly and disable the rule for that line, or define the alias via `const alias = E.A` outside the enum","For flag enums, verify each member uses a distinct bit: `1 << 0`, `1 << 1`, ..."],"exampleFix":"// before\nenum Status {\n  Active = 1,\n  Paused = 1,\n  Closed = 2,\n}\n\n// after\nenum Status {\n  Active = 1,\n  Paused = 3,\n  Closed = 2,\n}","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{\n  \"rules\": { \"typescript/no-duplicate-enum-values\": \"warn\" }\n}\n\n// unit test: fail when an enum gains duplicate values\nimport { Status } from './status';\nit('has unique enum values', () => {\n  const values = Object.values(Status);\n  expect(new Set(values).size).toBe(values.length);\n});","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer initialized enums (see prefer-enum-initializers) so every value is visible and reviewable","For flag enums, assign powers of two (1 << n) and never reuse a bit","Add the uniqueness unit test above next to important enums so CI catches regressions even without lint"],"tags":["typescript","lint","enum","correctness","oxlint"],"backgroundTag":"duplicate-enum-value","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}