{"record":{"id":"6abff7ff78a8b89a","repo":"oxc-project/oxc","slug":"found-identifier-name-with-the-same-name-as-a","errorCode":null,"errorMessage":"Found identifier '{name}' with the same name as a label.","messagePattern":"Found identifier '(.+?)' with the same name as a label\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_label_var.rs","lineNumber":9,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_label_var_diagnostic(name: &str, id_span: Span, label_span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Found identifier '{name}' with the same name as a label.\"))\n        .with_help(\"Rename either the variable or the label to avoid confusion.\")\n        .with_labels([\n            id_span.label(format!(\"Identifier '{name}' found here.\")),\n            label_span.label(\"Label with the same name.\"),\n        ])\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoLabelVar;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow labels that share a name with a variable.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// This rule aims to create clearer code by disallowing the bad practice of creating a label","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_label_var.rs#L1-L27","documentation":"Diagnostic from oxlint's eslint/no-label-var rule (crates/oxc_linter/src/rules/eslint/no_label_var.rs:9). It reports a labeled statement whose label has the same name as a variable in scope (e.g. 'var x = 1; x: while (true) {...}'). The label and the variable live in different namespaces so this is legal JavaScript, but readers commonly mistake break x / continue x for references to the variable.","triggerScenarios":"Declaring a variable and later using its name as a statement label: 'const speed = 5; speed: for (...) { break speed; }'. Both identifier references and label identifiers in the same file/scope collide.","commonSituations":"Code written by developers used to Go-style labels; refactoring where a loop gets a label that matches an existing variable; search-and-replace renames that create accidental name sharing.","solutions":["Rename the label to something that cannot be confused with data, e.g. 'outerLoop:' instead of the variable's name","Or rename the variable so it no longer collides with the label","Prefer removing the label entirely by restructuring the loop condition or extracting a function"],"exampleFix":"// before\nconst max = 10;\nmax: for (let i = 0; i < max; i++) {\n  for (let j = 0; j < max; j++) {\n    if (j > i) continue max;\n  }\n}\n\n// after\nconst max = 10;\nouterLoop: for (let i = 0; i < max; i++) {\n  for (let j = 0; j < max; j++) {\n    if (j > i) continue outerLoop;\n  }\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid statement labels entirely; most code never needs them","If labels are required, prefix them (outer:, rowLoop:) so they cannot collide with data names","Run oxlint in CI so no-label-var catches collisions at review time"],"tags":["lint","javascript","labels","naming","readability"],"backgroundTag":"label-variable-name-collision","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"}