- Install grunt-complexity by running
npm install grunt-complexity --save-dev
Then add a few lines to your grunt file to configure it (full example).
####Example
// JavaScript
grunt.initConfig({
// ...
complexity: {
js: {
//list of source files to analyze
src: ['javascript/*.js'],
options: {
// show only maintainability errors
errorsOnly: false,
// http://en.wikipedia.org/wiki/Cyclomatic_complexity
cyclomatic: 8,
// http://en.wikipedia.org/wiki/Halstead_complexity_measures
halstead: 8,
maintainability: 100
}
}
}
// ...
});
Unfortunately grunt-complexity doesn't support CoffeeScript yet, but it's only a pull request away if you have the time to implement it hint hint :) In the meantime you can use grunt-coffeelint as it has basic complexity checking and threshold enforcement.
First install grunt-coffeelint by running npm install grunt-coffeelint --save-dev
, then add a few lines to your grunt file to configure it (full example).
####Example
// JavaScript
grunt.initConfig({
// ...
coffeelint: {
//list of source files to analyze
all: ['coffeescript/*.coffee'],
options: {
cyclomatic_complexity: {
// http://en.wikipedia.org/wiki/Cyclomatic_complexity
value: 8,
level: 'error'
}
}
},
// ...
});