Jshint: add option or comment hint to ignore 'Unreachable break after return'

Created on 1 Dec 2012  ·  4Comments  ·  Source: jshint/jshint

I specifically ask about this condition because any straight-forward lex-compatible parser generator will use this pattern.

Most helpful comment

@Zugwalt what I ended up doing was modifying my generator to wrap the user specified code in an if(true) block.

For example:

switch(foo) {
    /* ... */
    case bar:
        if(true) {
            /* insert code here */
        }
        break;
    /* ... */
}

This is equivalent to the code without the braces and jshint doesn't complain :)

All 4 comments

I would love this as well as often when debugging I'll just throw in a return statement but then jshint (run automatically) complains

@Zugwalt what I ended up doing was modifying my generator to wrap the user specified code in an if(true) block.

For example:

switch(foo) {
    /* ... */
    case bar:
        if(true) {
            /* insert code here */
        }
        break;
    /* ... */
}

This is equivalent to the code without the braces and jshint doesn't complain :)

I don't know if this is older than this functionality, but I was just looking at the source, and the docs for JSLint, and this could do the trick as well

/*jshint -W027*/

The documentation says that sytax turns off those warnings everywhere, so I'm not sure if function scope works with those. Also I would like to note another use case for this is the use of a preprocessor. It would be nice to be able to lint before and after preprocessing if you take the time to set jshint options. So far I'm going to try the approach I just mentioned.

Update: It is function scoped.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

damyanpetev picture damyanpetev  ·  4Comments

timdown picture timdown  ·  7Comments

strugee picture strugee  ·  8Comments

nzakas picture nzakas  ·  10Comments

fbarda picture fbarda  ·  5Comments