{"record":{"id":"e5924b80cb26fe7a","repo":"oxc-project/oxc","slug":"duplicate-key-key","errorCode":null,"errorMessage":"Duplicate key '{key}'","messagePattern":"Duplicate key '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_dupe_keys.rs","lineNumber":13,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{ObjectProperty, ObjectPropertyKind, PropertyKey, PropertyKind},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse rustc_hash::{FxBuildHasher, FxHashMap};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_dupe_keys_diagnostic(first: Span, second: Span, key: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Duplicate key '{key}'\"))\n        .with_help(\"Consider removing the duplicated key\")\n        .with_labels([\n            first.label(\"Key is first defined here\"),\n            second.label(\"and duplicated here\"),\n        ])\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoDupeKeys;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow duplicate keys in object literals.\n    ///\n    /// This rule can be disabled for TypeScript code, as the TypeScript compiler\n    /// enforces this check.\n    ///","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_dupe_keys.rs#L1-L31","documentation":"This diagnostic comes from the `no_dupe_keys` rule in oxlint. It reports an object literal that defines the same key twice. The later value overwrites the earlier one at runtime, so the first pair is dead data. The rule stores each `PropertyKey` in a hash map and reports the second occurrence with labels on both spans.","triggerScenarios":"An object literal with a repeated key: `{ a: 1, a: 2 }`, a quoted and unquoted mix `{ 'x': 1, x: 2 }`, or numeric forms that hold the same value such as `{ 1: 'a', 0x1: 'b' }`. Spread properties do not count.","commonSituations":"A config object grows over many commits, and two people add the same key. Keys are renamed during a migration and the old key stays in one place. Option groups are copied and pasted.","solutions":["Delete one of the two pairs; the report labels the first definition and the duplicate.","Rename one key when both values matter.","Add a check to code review for large literal config objects."],"exampleFix":"// before\nconst config = {\n  retries: 2,\n  timeout: 500,\n  retries: 5,\n};\n\n// after\nconst config = {\n  retries: 5,\n  timeout: 500,\n};","handlingStrategy":"validation","validationCode":"// no reliable runtime check: the engine collapses duplicate keys silently\n// run oxlint on the file instead:\n//   oxlint src/config.js","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use TypeScript: a second identical key in one object literal is a compile error (ts1117).","Run oxlint in the editor so duplicate keys show while you type.","Build large option objects from small typed pieces, not by repeated literal edits."],"tags":["javascript","eslint","lint","objects","dead-code"],"backgroundTag":"lint-duplicate-object-key","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"}