Lint Rules

noUselessLabel (since v12.0.0)

This rule is recommended by Rome.

Disallow unnecessary labels.

If a loop contains no nested loops or switches, labeling the loop is unnecessary.

Source: https://eslint.org/docs/latest/rules/no-extra-label

Examples

Invalid

loop: while(a) {
    break loop;
}
complexity/noUselessLabel.js:2:11 lint/complexity/noUselessLabel  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

   Unnecessary label.
  
    1 │ loop: while(a) {
  > 2 │     break loop;
             ^^^^
    3 │ }
    4 │ 
  
   Suggested fix: Remove the unnecessary label.
    You can achieve the same result without the label.
  
    2 │ ····break·loop;
           ----- 

Valid

outer: while(a) {
    while(b) {
        break outer;
    }
}