{"record":{"id":"f84e0bdc479256b0","repo":"oxc-project/oxc","slug":"duplicate-class-member-member-name","errorCode":null,"errorMessage":"Duplicate class member: {member_name:?}","messagePattern":"Duplicate class member: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_dupe_class_members.rs","lineNumber":13,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse rustc_hash::FxHashMap;\n\nuse crate::{context::LintContext, rule::Rule};\n\nfn no_dupe_class_members_diagnostic(\n    member_name: &str, /*Class member name */\n    decl_span: Span,\n    re_decl_span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Duplicate class member: {member_name:?}\"))\n        .with_help(\"The last declaration overwrites previous ones, remove one of them or rename if both should be retained\")\n        .with_labels([\n            decl_span.label(format!(\"{member_name:?} is previously declared here\")),\n            re_decl_span.label(format!(\"{member_name:?} is re-declared here\")),\n        ])\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoDupeClassMembers;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow duplicate class members.\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_class_members.rs#L1-L31","documentation":"This diagnostic comes from the `no_dupe_class_members` rule in oxlint. It reports two members with the same name in one class body. At runtime the last member overwrites the earlier one, so the earlier member is dead code. The rule keeps member names in a hash map and reports each re-declaration with labels on both the first and the second span.","triggerScenarios":"Two methods, fields, or constructors with the same name in one class: `class A { foo() {} foo() {} }`. Getter/setter pairs with the same name form one property and stay allowed. The rule keys on the evaluated member name string.","commonSituations":"A merge conflict resolves to two methods with the same name. A method is copied with a plan to rename it, and the rename is forgotten. A large class hides the collision because the two members sit screens apart.","solutions":["Remove one of the two members, or rename one if both are needed.","If branches were merged, compare both bodies and keep the correct one.","Use the two labels in the report to jump to the first declaration and to the re-declaration.","Suppress in generated code with `// oxlint-disable-next-line no-dupe-class-members`."],"exampleFix":"// before\nclass Repo {\n  find(id) { return db.find(id); }\n  find(id) { return this.all().filter(x => x.id === id); }\n}\n\n// after\nclass Repo {\n  findById(id) { return db.find(id); }\n  findAllById(id) { return this.all().filter(x => x.id === id); }\n}","handlingStrategy":"validation","validationCode":"// codegen check: duplicate plain member names in a class body\nconst names = [...clsSrc.matchAll(/(?:^|\\n)\\s*(?:get\\s+|set\\s+|static\\s+|async\\s+|\\*\\s*)*([A-Za-z_$][\\w$]*)\\s*\\(/g)].map(m => m[1]);\nconst dup = names.filter((n, i) => names.indexOf(n) !== i);\nif (dup.length) throw new Error('duplicate class members: ' + dup);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run oxlint on changed files after every merge.","Keep classes small so all member names stay on one screen.","Name members after their behavior so copies are obvious."],"tags":["javascript","eslint","lint","classes","dead-code"],"backgroundTag":"lint-duplicate-class-member","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}