no-unreachable
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-unreachable"],
"exclude": ["no-unreachable"]
}
}
}Disallows the unreachable code after the control flow statements.
Because the control flow statements (return, throw, break and continue)
unconditionally exit a block of code, any statements after them cannot be
executed.
Invalid:
function foo() {
return true;
console.log("done");
}
function bar() {
throw new Error("Oops!");
console.log("done");
}
while (value) {
break;
console.log("done");
}
throw new Error("Oops!");
console.log("done");
function baz() {
if (Math.random() < 0.5) {
return;
} else {
throw new Error();
}
console.log("done");
}
for (;;) {}
console.log("done");
Valid:
function foo() {
return bar();
function bar() {
return 1;
}
}