简体   繁体   English

关闭JSHint中的循环复杂性

[英]Turn off cyclmatic complexity in JSHint

I am using JSHint and I want to turn off cyclomatic complexity. 我正在使用JSHint,我想关闭圈复杂度。

How can I do this? 我怎样才能做到这一点?

Let's say our function is named x. 假设我们的函数名为x。 Then we should just write this : 然后我们应该写这个:

function x () {
    /*jshint maxcomplexity:6 */
}

Where 6 is number js hint usually says it in console like this: 其中6是数字js提示通常在控制台中这样说:

static/desktop.blocks/days/days.js: line 57, col 27, This function's cyclomatic complexity is too high. static / desktop.blocks / days / days.js:line 57,col 27,此函数的圈复杂度太高。 (6) (6)

I tried at the top of my file to put the following: 我尝试在我的文件顶部放置以下内容:

/*jshint maxcomplexity:0 */

And was told 并被告知

Expected a small integer or 'false' and instead saw '0'. 期望一个小整数或'假'而是看到'0'。

So then tried the following 所以接下来试了一下

/*jshint maxcomplexity:false */

And found that it does turn off the cyclomatic complexity warnings. 并发现它确实关闭了圈复杂度警告。

我们可以通过配置文件.jshintrc关闭jshint中函数的圈复杂度,如下所示:

"maxcomplexity" : false,       // {int} Max cyclomatic complexity per function

Beware. 谨防。 JSHint does not compute cyclomatic complexity correctly. JSHint无法正确计算圈复杂度。 Example: 例:

function result(a, b, c) {
  return a || b || c;
}

Complexity here is 1; 这里的复杂性是1; no branches, no loops. 没有分支,没有循环。 JSHint errors if you set maxcomplexity to less than 3. The REPL at http://www.jshint.com also reports 3. JSHint错误,如果你设置maxcomplexity到小于3的REPL在http://www.jshint.com也报告3。

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

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