noDeadCode (since v0.7.0)
Disallow unreachable code
Examples
Invalid
function example() {
return;
neverCalled();
} warning[js/noDeadCode]: This code is unreachable
┌─ js/noDeadCode.js:3:5
│
2 │ return;
│ ------- This statement will return from the function ...
3 │ neverCalled();
│ -------------- ... before it can reach this code
function example() {
for(let i = 0; i < 10; ++i) {
break;
}
} warning[js/noDeadCode]: This code is unreachable
┌─ js/noDeadCode.js:2:28
│
2 │ for(let i = 0; i < 10; ++i) {
│ --- This code will never be reached ...
3 │ break;
│ ------ ... because this statement will break the flow of the code beforehand
function example() {
for(const key in value) {
continue;
neverCalled();
}
} warning[js/noDeadCode]: This code is unreachable
┌─ js/noDeadCode.js:4:9
│
3 │ continue;
│ --------- This statement will continue the loop ...
4 │ neverCalled();
│ -------------- ... before it can reach this code