Skip to main content

noUnreachable (since v0.7.0)

Disallow unreachable code

Examples

Invalid

function example() {
return;
neverCalled();
}
nursery/noUnreachable.js:3:5 lint/nursery/noUnreachable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This code is unreachable
  
   ... before it can reach this code
  
     nursery/noUnreachable.js:3:5
    
  3      neverCalled();
         ^^^^^^^^^^^^^^
  
   This statement will return from the function ...
  
     nursery/noUnreachable.js:2:5
    
  2      return;
         ^^^^^^^
  
function example() {
for(let i = 0; i < 10; ++i) {
break;
}
}
nursery/noUnreachable.js:2:28 lint/nursery/noUnreachable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This code is unreachable
  
   This code will never be reached ...
  
     nursery/noUnreachable.js:2:28
    
  2      for(let i = 0; i < 10; ++i) {
                                ^^^
  
   ... because this statement will break the flow of the code beforehand
  
     nursery/noUnreachable.js:3:9
    
  3          break;
             ^^^^^^
  
function example() {
for(const key in value) {
continue;
neverCalled();
}
}
nursery/noUnreachable.js:4:9 lint/nursery/noUnreachable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This code is unreachable
  
   ... before it can reach this code
  
     nursery/noUnreachable.js:4:9
    
  4          neverCalled();
             ^^^^^^^^^^^^^^
  
   This statement will continue the loop ...
  
     nursery/noUnreachable.js:3:9
    
  3          continue;
             ^^^^^^^^^