简体   繁体   中英

How can I disable 'falls through' checker of jshint in .jshintrc?

I want to disable 'falls through' checker of jshint in mt .jshintrc file. However, the checker seems to be enabled by default.

http://jshint.com/docs/#options

By default JSHint warns when you omit break or return statements within switch statements:

switch (cond) {
case "one":
  doSomething(); // JSHint will warn about missing 'break' here.
case "two":
  doSomethingElse();
}

I couldn't find out the checker id from the official web site so I cannot update the .jshintrc file.

Could you let me know how I can disable 'falls through' checker and where I can find out the full checker list provided by jshint.

Thanks for your help in advance.

You're looking for the key found here .

Specifically:

"-W086": true, //allow fall-through

I'm pretty sure the answer by SomeKittens should work, but I'd just like to put up an alternative view since I was brought here by Google when looking up what rule W086 was.

There are some very good reasons for jshint to have this default behaviour. For one, most developers that sees code like this when looking for what's causing a bug will likely latch on to it and spend some time attempting to determine whether or not the fall-through is intentional (after all, it's a very common mistake), occasionally even going so far as to "fix" it pre-emptively.

As such, I'd advise keeping this default behaviour, and specifically overriding it with the in-line override mechanism provided in order to ensure that other developers realise that you in fact intended the fall-through.

Personally I'd even go so far as to add a comment about it so there's no doubt, even if you don't know the jshint rule numbers:

// Fall-through required in switch statement.
/* jshint -W086 */
switch(...) { ... }
/* jshint +W086 */

Alternatively, you can simply add /* falls through */ when there is an intentional fall-through as jshint recognises this as well (allowing you to safely mix fall-through's and breaks without ambiguity):

switch(...) {
    case ...:
        ...
        /* falls through */
    case ...:
        ...
        break;
    case ...:
        ...
        /* falls through */
    default:
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM