{"record":{"id":"a5e37b51b8b9fe76","repo":"oxc-project/oxc","slug":"this-label-label-name-is-unnecessary","errorCode":null,"errorMessage":"This label '{label_name}' is unnecessary","messagePattern":"This label '(.+?)' is unnecessary","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/eslint/no_extra_label.rs","lineNumber":10,"sourceCode":"use oxc_ast::{AstKind, ast::LabelIdentifier};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_extra_label_diagnostic(label: &LabelIdentifier) -> OxcDiagnostic {\n    let label_name = &label.name;\n    OxcDiagnostic::warn(format!(\"This label '{label_name}' is unnecessary\"))\n        .with_help(format!(\"Remove this label. It will have the same result because the labeled statement '{label_name}' has no nested loops or switches\"))\n        .with_label(label.span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoExtraLabel;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow unnecessary labels.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// If a loop contains no nested loops or switches, labeling the loop is unnecessary.\n    /// ```js\n    /// A: while (a) {\n    ///     break A;","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_extra_label.rs#L1-L28","documentation":"Diagnostic from oxlint's no-extra-label rule (ESLint port, part of eslint:recommended). It reports a label attached to a statement that contains no nested loops or switches. Because there is nothing nested, 'break label' / 'continue label' resolves to exactly the same behavior as a plain break/continue, so the label is pure noise and the rule asks you to delete it.","triggerScenarios":"outer: while (cond) { ... break outer; } where the loop body has no inner loop or switch; loop1: for (;;) { doWork(); continue loop1; } with nothing nested; any 'identifier :' label directly on a loop whose body is flat.","commonSituations":"Leftover labels after an inner loop was extracted into a function; code copied from break-out-of-nested-loops patterns where the nesting was later removed; mechanical label prefixes added by old tooling.","solutions":["Delete the label from the statement and from the matching break/continue.","If you do need to jump out of a nested loop, keep the label on the outer loop only (that usage is allowed).","Suppress with // oxlint-disable-next-line eslint/no-extra-label if a tool depends on the label."],"exampleFix":"// before\nouter: while (queue.length) {\n  process(queue.shift());\n  if (done) break outer;\n}\n\n// after\nwhile (queue.length) {\n  process(queue.shift());\n  if (done) break;\n}","handlingStrategy":"validation","validationCode":"const labeledLoops = [...source.matchAll(/^(\\w+)\\s*:\\s*(?:for|while|do)\\b/gm)];\n// then confirm each hit has no nested loop/switch before shipping","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use labels only to break out of nested loops or switches.","When you delete an inner loop, delete its parent label in the same change.","Gate merges with npx oxlint -A all -D no-extra-label src/."],"tags":["eslint","oxlint","lint","labels","dead-code"],"backgroundTag":"redundant-label","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"}