deno_lint logodeno_lint

All rules/no-unreachable

no-unreachable

Recommended

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;
  }
}