I am using JSHint and I want to turn off cyclomatic complexity.
How can I do this?
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.
We can turn off the cyclomatic complexity of functions in jshint via the config file .jshintrc like this:
"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.