no-unused-labels
NOTE: this rule is part of the
recommended rule set.Enable full set in
deno.json:{
"lint": {
"rules": {
"tags": ["recommended"]
}
}
}Enable full set using the Deno CLI:
deno lint --rules-tags=recommended
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the
include or exclude array in deno.json:{
"lint": {
"rules": {
"include": ["no-unused-labels"],
"exclude": ["no-unused-labels"]
}
}
}Disallows unused labels.
A label that is declared but never used is most likely developer's mistake. If that label is meant to be used, then write a code so that it will be used. Otherwise, remove the label.
Invalid:
LABEL1:
while (true) {
console.log(42);
}
LABEL2:
for (let i = 0; i < 5; i++) {
console.log(42);
}
LABEL3:
for (const x of xs) {
console.log(x);
}
Valid:
LABEL1:
while (true) {
console.log(42);
break LABEL1;
}
LABEL2:
for (let i = 0; i < 5; i++) {
console.log(42);
continue LABEL2;
}
for (const x of xs) {
console.log(x);
}