Skip to content

Latest commit

 

History

History
65 lines (52 loc) · 1.96 KB

complexity.md

File metadata and controls

65 lines (52 loc) · 1.96 KB

Complexity Threshold Enforcement for AngularJS

JavaScript

Install Dependencies

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
      }
    }
  }
  // ...
});

screenshot screenshot

CoffeeScript

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'
      }
    }
  },
  // ...
});