UNPKG

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