{"record":{"id":"ce94417cdcf36677","repo":"oxc-project/oxc","slug":"labeled-statement-is-not-allowed","errorCode":null,"errorMessage":"Labeled statement is not allowed","messagePattern":"Labeled statement is not allowed","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_labels.rs","lineNumber":19,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{LabelIdentifier, Statement},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::NodeId;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_labels_diagnostic(message: &'static str, label_span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(message)\n        .with_help(\"Consider refactoring the code to eliminate the need for labels.\")\n        .with_label(label_span)\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoLabels {\n    /// If set to `true`, this rule ignores labels which are sticking to loop statements.\n    /// Examples of **correct** code with this option set to `true`:\n    /// ```js\n    /// label:\n    ///     while (true) {\n    ///         break label;\n    ///     }\n    /// ```\n    allow_loop: bool,\n    /// If set to `true`, this rule ignores labels which are sticking to switch statements.\n    /// Examples of **correct** code with this option set to `true`:","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_labels.rs#L1-L37","documentation":"Diagnostic from oxlint's eslint/no-labels rule (crates/oxc_linter/src/rules/eslint/no_labels.rs:19). With the rule enabled, it reports any labeled statement that the current options do not exempt: by default all labels are disallowed; with allowLoop=true only labels attached to loop statements are ignored, and with allowSwitch=true labels on switch statements are ignored. Labels are a rarely used, error-prone control-flow feature that most style guides ban.","triggerScenarios":"Any 'name:' prefix on a statement: 'label: while (true) {...}' (allowed only if allowLoop is true), 'label: switch (a) {...}' (allowed only if allowSwitch is true), and always for 'label: { ... }' or 'label: if (a) {...}'.","commonSituations":"Enabling the rule as part of migrating an ESLint config (e.g. airbnb-style or strict presets) to oxlint; legacy code using outer-loop labels; generated or ported code from languages where labels are idiomatic.","solutions":["Remove the label and restructure: move the labeled loop into a function and use return instead of break label","If the label only breaks out of nested loops, use a flag variable or Array.prototype.some/every as an alternative","If loop labels are intentionally used, set \"allowLoop\": true (and \"allowSwitch\": true where needed) in the no-labels options in .oxlintrc.json"],"exampleFix":"// before\nouter:\n  while (true) {\n    for (const x of xs) {\n      if (bad(x)) break outer;\n    }\n  }\n\n// after\nfunction process(xs) {\n  while (true) {\n    for (const x of xs) {\n      if (bad(x)) return;\n    }\n  }\n}","handlingStrategy":"validation","validationCode":"// CI guard: reject any labeled statement before it lands\nimport { execSync } from 'node:child_process';\ntry {\n  execSync('npx oxlint --deny-labels src/ 2>/dev/null || grep -rnE \"^\\\\s*[A-Za-z_$][\\\\w$]*\\\\s*:\\\\s*(while|for|switch|\\\\{)\" src/', { stdio: 'pipe' });\n  process.exitCode = 1;\n} catch {\n  /* clean */\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer extracting functions with early return over labels for loop control","Enable no-labels in shared configs early in a project so labels never accumulate","Document the allowLoop/allowSwitch exceptions you grant and why"],"tags":["lint","javascript","labels","control-flow","style"],"backgroundTag":"labeled-statements","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"}