I am using JSHint and I want to turn off cyclomatic complexity.
How can I do this?
Let's say our function is named 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:
static/desktop.blocks/days/days.js: line 57, col 27, This function's cyclomatic complexity is too high. (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'.
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. Example:
function result(a, b, c) {
return a || b || c;
}
Complexity here is 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.
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.