Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 457399

Summary: [eslint] Unreachable code warning should mark all statements as one problem
Product: [ECD] Orion Reporter: Michael Rennie <Michael_Rennie>
Component: JS ToolsAssignee: Michael Rennie <Michael_Rennie>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 8.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Screen shot none

Description Michael Rennie CLA 2015-01-13 23:05:27 EST
Consider the following snippet:

var foo = 10;
switch(foo) {
    case 1: {
        throw e;
        f = 10;
        break;
    }
}

When linted you will see two warnings for unreachable code: 'f=10;' and 'break;'. both of these statements should be marked as one problem since all of it is unreachable. This would also simplify fixing the problem - rather than having to apply N fixes for N unreachable statements, there would be one fix for N statements.
Comment 1 John Arthorne CLA 2015-01-28 21:24:39 EST
I hit a similar problem, except only the last statement was indicated as a warning. There was only a quick fix available for removing the last line. See screenshot.
Comment 2 John Arthorne CLA 2015-01-28 21:25:21 EST
Created attachment 250329 [details]
Screen shot
Comment 3 Michael Rennie CLA 2015-01-29 09:26:27 EST
(In reply to John Arthorne from comment #1)
> I hit a similar problem, except only the last statement was indicated as a
> warning. There was only a quick fix available for removing the last line.
> See screenshot.

That is correctly marked. Any function or var declarations after a returnable statement are 'hoisted' to the start of the enclosing functional scope (so they are in fact not unreachable).

For some more info on hoisting: http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html
Comment 4 Michael Rennie CLA 2015-05-08 11:02:15 EDT
The more I think about this one, the more it kind of makes sense to mark each expression by itself, rather than try to make one big annotation - the advantages are that we can find specifically the offending expressions rather than trying to parse out / find nodes from a huge annotation.

Closing wontfix