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:
/// ```javascriptView on GitHub (pinned to e1e7af627c)
Solutions
- Delete the unused label and its colon.
- If a labeled break was intended, restore break label; at the right spot.
- 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
- Remove labels whenever you remove or un-nest the loops they named.
- Run oxlint --fix before commit; unused label removal is mechanical and safe.
- Prefer extracting functions over labeled control flow in new code.
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
- This label '{label_name}' is unnecessary
- Redundant Boolean call
- Unreachable code.
- Invalid loop. Its body allows only one iteration.
- '{name}' is defined but never used.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/66f05a2ba7396c09.
Report an issue: GitHub.