oxc-project/oxc · warning · OxcDiagnostic

'{label_name}:' is defined but never used.

Error message

'{label_name}:' is defined but never used.

What it means

Diagnostic from oxlint's no-unused-labels rule. A label declared on a loop or block is never targeted by any break/continue with that name, so it is dead syntax, typically leftover after the labeled break or the inner loop was removed.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_unused_labels.rs:9

use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{context::LintContext, rule::Rule};

fn no_unused_labels_diagnostic(label_name: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("'{label_name}:' is defined but never used.")).with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct NoUnusedLabels;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow unused labels.
    ///
    /// ### Why is this bad?
    ///
    /// Labels that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring.
    ///
    /// ### Examples
    ///
    /// Examples of **incorrect** code for this rule:
    /// ```javascript

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Delete the unused label and its colon.
  2. If a labeled break was intended, restore break label; at the right spot.
  3. Run oxlint --fix; removing an unused label is a purely mechanical, safe fix.

Example fix

// before
outer: for (const a of xs) {
  for (const b of ys) { handle(a, b); }
}
// after
for (const a of xs) {
  for (const b of ys) { handle(a, b); }
}
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: outer: for (...) { for (...) { ... } } with no break outer; or continue outer; anywhere in the function.

Common situations: The inner loop or the labeled break was deleted during refactoring; a flag or early return replaced the labeled control flow; generated code emits labels unconditionally.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/66f05a2ba7396c09. Report an issue: GitHub.