oxc-project/oxc · warning · OxcDiagnostic

Label in continue statement is not allowed

Error message

Label in continue statement is not allowed

What it means

Diagnostic from oxlint's eslint/no-labels rule (crates/oxc_linter/src/rules/eslint/no_labels.rs:19). It reports 'continue someLabel;' — a form that jumps to the next iteration of an outer labeled loop. Because continue-with-label only targets loops, it is flagged whenever the labeled statement is disallowed by the active no-labels options; it is the control-flow construct style guides most want removed since it behaves like a restricted goto.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_labels.rs:19

use oxc_ast::{
    AstKind,
    ast::{LabelIdentifier, Statement},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::NodeId;
use oxc_span::Span;
use schemars::JsonSchema;
use serde::Deserialize;

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

fn no_labels_diagnostic(message: &'static str, label_span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(message)
        .with_help("Consider refactoring the code to eliminate the need for labels.")
        .with_label(label_span)
}

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoLabels {
    /// If set to `true`, this rule ignores labels which are sticking to loop statements.
    /// Examples of **correct** code with this option set to `true`:
    /// ```js
    /// label:
    ///     while (true) {
    ///         break label;
    ///     }
    /// ```
    allow_loop: bool,
    /// If set to `true`, this rule ignores labels which are sticking to switch statements.
    /// Examples of **correct** code with this option set to `true`:

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Restructure so the inner work is a function: use return to skip to the next outer iteration
  2. Replace the pattern with a guard condition on the outer loop body or use array iteration methods with early exit
  3. If intentional, allow loop labels via "allowLoop": true in the no-labels options

Example fix

// before
outer: for (const user of users) {
  for (const item of user.items) {
    if (item.skip) continue outer;
    handle(item);
  }
}

// after
for (const user of users) {
  if (user.items.some((item) => item.skip)) continue;
  for (const item of user.items) handle(item);
}
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: 'continue label;' inside an inner loop where 'label:' marks an outer loop or if-statement, e.g. 'outer: while (a) { while (b) { continue outer; } }'.

Common situations: Simulation/matrix code that skips to the next outer iteration; legacy code written before Array methods (some/every/find) were common; codebases adopting a strict shared lint config that enables no-labels.

Related errors


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