{"record":{"id":"ad3808d9a9193d31","repo":"oxc-project/oxc","slug":"name-is-already-defined","errorCode":null,"errorMessage":"'{name}' is already defined.","messagePattern":"'(.+?)' is already defined\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_redeclare.rs","lineNumber":15,"sourceCode":"use javascript_globals::GLOBALS_BUILTIN;\n\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_redeclare_diagnostic(name: &str, decl_span: Span, re_decl_span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"'{name}' is already defined.\"))\n        .with_help(\"Use a different variable name or remove the duplicate declaration.\")\n        .with_labels([\n            decl_span.label(format!(\"'{name}' is already defined.\")),\n            re_decl_span.label(\"It can not be redeclared here.\"),\n        ])\n}\n\nfn no_redeclare_as_builtin_in_diagnostic(name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"'{name}' is already defined as a built-in global variable.\"))\n        .with_help(\"Use a different variable name to avoid shadowing the built-in global.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoRedeclare {\n    /// When set `true`, it flags redeclaring built-in globals (e.g., `let Object = 1;`).\n    builtin_globals: bool,","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_redeclare.rs#L1-L33","documentation":"Diagnostic from oxlint's port of ESLint `no-redeclare`. It fires when the same binding name is declared more than once within one scope. JS only permits this for `var`/`function` (and TS redeclare forms), and it usually means a bug or a merge leftover. The primary label points at the original declaration, the secondary label at the redeclaration.","triggerScenarios":"`run_once` walks every symbol in the semantic scoping data and reports each adjacent pair in `symbol_redeclarations`: `var a = 1; var a = 2;`, two non-`declare` function declarations of the same name in one scope, `var f; function f(){}`. In TypeScript sources, TS redeclaration entries are compared too (`class C {} var C;`).","commonSituations":"Copy-paste or git-merge leftovers; migrating loose scripts into a linted repo; TypeScript code that tries to overload functions by declaring them twice instead of using a single signature with union types.","solutions":["Delete or rename the duplicate so each name is declared once per scope.","Replace the second declaration with a plain assignment (`a = 10` instead of `var a = 10`).","For intended overloading in TS, use one function with union parameter types, or separate the variants behind `declare function` in a namespace.","If the duplication is intentional, add an `oxlint-ignore no-redeclare` comment or disable the rule in .oxlintrc."],"exampleFix":"// before\nvar a = 3;\nvar a = 10;\n\n// after\nvar a = 3;\na = 10;","handlingStrategy":"validation","validationCode":"// Pre-commit check: catch duplicate var/function names per top-level scope\nconst { execSync } = require('node:child_process');\nconst src = require('node:fs').readFileSync(process.argv[2], 'utf8');\nconst seen = new Set();\nfor (const m of src.matchAll(/(?:var|let|const|function)\\s+([A-Za-z_$][\\w$]*)/g)) {\n  if (seen.has(m[1])) {\n    console.error(`duplicate declaration: ${m[1]}`);\n    process.exitCode = 1;\n  }\n  seen.add(m[1]);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `npx oxlint` in a pre-commit hook (husky/lint-staged) so duplicates never land on main.","Prefer `const`/`let` over `var` — block-scoped bindings make accidental redeclaration a SyntaxError instead of a lint hit.","After merge conflicts, grep the resolved file for repeated declaration names before committing."],"tags":["lint","eslint","no-redeclare","variables","scoping"],"backgroundTag":"duplicate-variable-declaration","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"}