14

I am using JSHint and I want to turn off cyclomatic complexity.

How can I do this?

OmG
  • 18,337
  • 10
  • 57
  • 90
user2950593
  • 9,233
  • 15
  • 67
  • 131
  • 1
    How are you using jshint? Are you using it with grunt? Which NPM? You need to clarify that if you want an accurate answer. – Munim Nov 08 '13 at 11:10
  • Did you read the [documentation](http://www.jshint.com/docs/)? – Andreas Nov 08 '13 at 11:13
  • yes with grunt for example i am enabling it just writing in terminal jshint static server where static server are my folders i need to check with jshint – user2950593 Nov 08 '13 at 11:14
  • yes of course i guess it is the first link i found – user2950593 Nov 08 '13 at 11:15
  • This option lets you control cyclomatic complexity throughout your code. Cyclomatic complexity measures the number of linearly independent paths through a program's source code. Read more about cyclomatic complexity on Wikipedia. it is all=) – user2950593 Nov 08 '13 at 11:16

4 Answers4

16

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)

user2950593
  • 9,233
  • 15
  • 67
  • 131
4

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.

Tim Tisdall
  • 9,914
  • 3
  • 52
  • 82
0

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
Alee
  • 740
  • 7
  • 19
-3

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.

remy70
  • 1