oxc-project/oxc · error
This label '{label_name}' is unnecessary
Error message
This label '{label_name}' is unnecessary What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_extra_label.rs:10
use oxc_ast::{AstKind, ast::LabelIdentifier};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use crate::{AstNode, context::LintContext, rule::Rule};
fn no_extra_label_diagnostic(label: &LabelIdentifier) -> OxcDiagnostic {
let label_name = &label.name;
OxcDiagnostic::warn(format!("This label '{label_name}' is unnecessary"))
.with_help(format!("Remove this label. It will have the same result because the labeled statement '{label_name}' has no nested loops or switches"))
.with_label(label.span)
}
#[derive(Debug, Default, Clone)]
pub struct NoExtraLabel;
declare_oxc_lint!(
/// ### What it does
///
/// Disallow unnecessary labels.
///
/// ### Why is this bad?
///
/// If a loop contains no nested loops or switches, labeling the loop is unnecessary.
/// ```js
/// A: while (a) {
/// break A;View on GitHub (pinned to e1e7af627c)
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.
Example fix
// before
outer: while (queue.length) {
process(queue.shift());
if (done) break outer;
}
// after
while (queue.length) {
process(queue.shift());
if (done) break;
} Defensive patterns
Strategy: validation
Validate before calling
const labeledLoops = [...source.matchAll(/^(\w+)\s*:\s*(?:for|while|do)\b/gm)]; // then confirm each hit has no nested loop/switch before shipping
Prevention
- 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/.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Redundant Boolean call
- '{label_name}:' is defined but never used.
- Empty array binding pattern
- Empty object binding pattern
- Unexpected constant {lhs_name} on the left-hand side of a {e
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/a5e37b51b8b9fe76.
Report an issue: GitHub.