no-unused-labels

Disallow labels that no break or continue refers to

warn by defaultfixable

A label only does something when a break or continue names it. If nothing names it, either the label is left over, or the break that should name it leaves the wrong loop.

An unused label can also be a failed object literal. In item => { id: item.id } the braces are a function body and id: is a label, so the function returns undefined.

--fix removes the label.

This rule is on by default.

Configure#

On by default as a warning. To turn it off:

bunfig.toml
[lint.rules]
"no-unused-labels" = "off" # or "error"

Examples#

Reported. The break only leaves the inner loop:

example.js1 problem
rows: for (const row of table) {
  for (const cell of row) {
    if (cell.isEmpty) break;
  }
}
example.js1 problem
const ids = items.map(item => { id: item.id });
example.jsNo problems
rows: for (const row of table) {
  for (const cell of row) {
    if (cell.isEmpty) break rows;
  }
}
example.jsNo problems
const ids = items.map(item => ({ id: item.id }));