UNPKG

3.31 kBMarkdownView Raw
1# Grunt-Complexity
2
3[![Build Status](https://travis-ci.org/vigetlabs/grunt-complexity.svg)](https://travis-ci.org/vigetlabs/grunt-complexity)
4
5A [grunt](http://github.com/gruntjs/grunt/) task that utilizes
6[complexity-report](https://github.com/philbooth/complexityReport.js)
7to evaluate the complexity and maintainability of code.
8
9## Versions
10
11- Use version 0.0.7 for Grunt 0.3.x
12- Use versions 0.1.x for Grunt 0.4.x
13
14![screenshot](https://raw.github.com/vigetlabs/grunt-complexity/master/example.png)
15![screenshot](https://raw.github.com/vigetlabs/grunt-complexity/master/complexity.png)
16
17## Usage
18
19```bash
20npm install grunt-complexity --save-dev
21```
22
23Within your grunt file:
24
25```javascript
26 // Project configuration.
27 grunt.initConfig({
28
29 complexity: {
30 generic: {
31 src: ['grunt.js', 'tasks/grunt-complexity.js'],
32 exclude: ['doNotTest.js'],
33 options: {
34 breakOnErrors: true,
35 jsLintXML: 'report.xml', // create XML JSLint-like report
36 checkstyleXML: 'checkstyle.xml', // create checkstyle report
37 pmdXML: 'pmd.xml', // create pmd report
38 errorsOnly: false, // show only maintainability errors
39 cyclomatic: [3, 7, 12], // or optionally a single value, like 3
40 halstead: [8, 13, 20], // or optionally a single value, like 8
41 maintainability: 100,
42 hideComplexFunctions: false, // only display maintainability
43 broadcast: false // broadcast data over event-bus
44 }
45 }
46 }
47
48
49 });
50
51 grunt.loadNpmTasks('grunt-complexity');
52 grunt.registerTask('default', 'complexity');
53```
54
55## What is Cyclomatic and Halstead?
56
57Documentation on this to come. For now, see [jscomplexity.org](http://jscomplexity.org/complexity)
58
59## Reporter
60
61Set the `broadcast` option to `true` to send the aggregated data over the
62grunt-event bus.
63
64Emitted events are:
65
66* `grunt-complexity.start`
67* `grunt-complexity.maintainability, payload`
68* `grunt-complexity.end`
69
70```js
71// payload of grunt-complexity.maintainability
72{
73 filepath: /path/to/file,
74 valid: true|false,
75 maintainability: 123.42
76}
77```
78
79## Contributing
80
81This repo has a submodule, so after you `npm install`, you'll want to run:
82
83```bash
84git submodule init
85git submodule update
86cd test/grunt.0.4
87npm install
88cd ...
89```
90
91Tests can be run with `npm test`.
92
93## License
94
95`grunt-complexity` is released under the [MIT License](http://opensource.org/licenses/MIT).
96
97## Contributors
98
99- Nate Hunzaker([nhunzaker](https://github.com/nhunzaker))
100- Golo Roden ([goloroden](https://github.com/goloroden))
101- Tomasz Drwięga ([tomusdrw](https://github.com/tomusdrw))
102- Doug Avery ([averyvery](https://github.com/averyvery))
103- Jozsef Kozma ([jzsfkzm](https://github.com/jzsfkzm))
104- Patrick Williams [(pwmckenna](https://github.com/pwmckenna))
105- Luís Couto ([Couto](https://github.com/Couto))
106- Roman Liutikov ([roman01la](https://github.com/roman01la))
107- Nick Weingartner ([streetlight](https://github.com/streetlight))
108- David Linse ([davidlinse](https://github.com/davidlinse))
109- Tim Carry ([pixelastic](https://github.com/pixelastic))
110
111***
112
113<a href="http://code.viget.com">
114 <img src="http://code.viget.com/github-banner.png" alt="Code At Viget">
115</a>
116
117Visit [code.viget.com](http://code.viget.com) to see more projects from [Viget.](https://viget.com)