no-extra-label
Disallow labels on break and continue that name the innermost loop or switch
fixable
break and continue without a label already apply to the innermost loop or switch. Naming that same statement's label changes nothing, and it sends the reader looking for an outer loop that isn't there.
--fix removes the label after break or continue.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"no-extra-label" = "error" # or "warn"Examples#
example.js1 problem
search: for (const item of items) {
if (item.id === id) {
select(item);
break searchThis label search is unnecessary.;
}
}example.jsNo problems
for (const item of items) {
if (item.id === id) {
select(item);
break;
}
}You do need a label to leave an outer loop from an inner one:
example.jsNo problems
rows: for (const row of table) {
for (const cell of row) {
if (cell === target) {
break rows;
}
}
}