no-unreachable
eslint
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"no-unreachable": "error",
},
},
];Disallow unreachable code after return, throw, continue, and break statements
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");class C extends B {
#x; // unreachable
#y = 1; // unreachable
a; // unreachable
b = 1; // unreachable
constructor() {
return {};
}
}function foo() {
return bar();
function bar() {
return 1;
}
}
function bar() {
return x;
var x;
}
switch (foo) {
case 1:
break;
var x;
}class D extends B {
#x;
#y = 1;
a;
b = 1;
constructor() {
super();
}
}
class E extends B {
#x;
#y = 1;
a;
b = 1;
// implicit constructor always calls `super()`
}
class F extends B {
static #x;
static #y = 1;
static a;
static b = 1;
constructor() {
return {};
}
}Examples from the ESLint documentation.
no-unreachable
eslint
export default [
{
rules: {
"no-unreachable": "error",
},
},
];no-unreachable
eslint plugin · correctness
{
"rules": {
"no-unreachable": "error"
}
}correctness/noUnreachable
correctness · since 1.0.0
{
"linter": {
"rules": {
"correctness": {
"noUnreachable": "error"
}
}
}
}Disallow calling global object properties as functions
Disallow reassigning function declarations
Disallow unnecessary boolean casts
Disallow duplicate keys in object literals
Disallow this/super before calling super() in constructors