{"record":{"id":"f51e5eb24f5caa80","repo":"oxc-project/oxc","slug":"label-in-break-statement-is-not-allowed","errorCode":null,"errorMessage":"Label in break statement is not allowed","messagePattern":"Label in break 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). It reports 'break someLabel;' where the referenced labeled statement is not exempted by the rule options — the break-with-label form only exists to exit a labeled enclosing statement, so once no-labels bans the label this usage is flagged together with it. Switch statements are exempt only when allowSwitch is set.","triggerScenarios":"'break label;' inside nested loops referring to an outer labeled loop (flagged unless the label is on a switch and allowSwitch=true); 'break label;' inside a labeled switch block; any break carrying a label that the options do not permit.","commonSituations":"Deeply nested loop cleanup code using 'break outer;'; converting an ESLint config that had no-labels enabled and finding old loop-exit code flagged; labels on switch statements used as a goto substitute.","solutions":["Replace 'break label;' with a return by extracting the loop nest into a function","Rewrite the exit condition with a boolean flag or restructure the loops so a plain break suffices","Where the pattern is deliberate, enable \"allowLoop\": true / \"allowSwitch\": true in the no-labels options"],"exampleFix":"// before\nouter: for (const row of rows) {\n  for (const cell of row) {\n    if (cell === null) break outer;\n  }\n}\n\n// after\nfunction hasNull(rows) {\n  for (const row of rows) {\n    for (const cell of row) {\n      if (cell === null) return true;\n    }\n  }\n  return false;\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Model early exit from nested loops as a function with return","Use some()/every()/find() instead of break-with-label scans","If labels must stay, configure allowLoop/allowSwitch explicitly rather than inline disables"],"tags":["lint","javascript","labels","break","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"}