简体   繁体   English

如何禁用.jshintrc中jshint的“掉线”检查器?

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

I want to disable 'falls through' checker of jshint in mt .jshintrc file. 我想在mt .jshintrc文件中禁用jshint的“掉线”检查器。 However, the checker seems to be enabled by default. 但是,检查器似乎默认情况下处于启用状态。

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

By default JSHint warns when you omit break or return statements within switch statements: 默认情况下,当您在switch语句中省略break或return语句时,JSHint会发出警告:

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. 我无法从官方网站上找到检查器ID,因此无法更新.jshintrc文件。

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. 您能否让我知道如何禁用“掉线”检查器以及在哪里可以找到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. 我非常确定SomeKittens的答案应该可行,但是我想提出一个替代视图,因为我是Google在查询W086规则时带到这里的。

There are some very good reasons for jshint to have this default behaviour. jshint具有此默认行为的理由非常充分。 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: 就个人而言,即使您不知道jshint规则编号,我什至会对此添加评论,这是毫无疑问的:

// 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): 或者,您可以简单地添加/* falls through */ jshint /* falls through */ ,因为jshint识别出此跌落(允许您安全地将jshint和中断混合在一起):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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