complexity-report
Advanced tools
Comparing version 0.7.0 to 0.8.0
{ | ||
"name": "complexity-report", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"author": "Phil Booth <pmbooth@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "A tool for reporting code complexity metrics in JavaScript projects.", |
@@ -13,2 +13,4 @@ # complexityReport.js | ||
[Here is an example report][eg]. | ||
The tool can be configured to fail | ||
@@ -52,2 +54,6 @@ when complexity metrics pass a specified threshold, | ||
The tool will automatically | ||
recursively read files from any directories | ||
that it encounters. | ||
#### Options | ||
@@ -78,4 +84,5 @@ | ||
Currently there are four output formats supported: | ||
Currently there are five output formats supported: | ||
`plain`, | ||
`markdown`, | ||
`minimal`, | ||
@@ -125,2 +132,4 @@ `json` | ||
defaults to `false`. | ||
* `newmi`: Boolean indicating whether the maintainability | ||
index should be rebased on a scale from 0 to 100. | ||
@@ -137,5 +146,3 @@ The returned report is an object | ||
There are two projects | ||
that generate chart visualizations | ||
of complexiytReport.js metrics: | ||
Visualizations: | ||
@@ -145,2 +152,6 @@ * [Gleb Bahmutov][gleb]'s [js-complexity-viz]; | ||
Build tasks: | ||
* [Viget Labs][viget]' [grunt-complexity]. | ||
## Development | ||
@@ -197,2 +208,3 @@ | ||
[ci-status]: http://travis-ci.org/#!/philbooth/complexityReport.js | ||
[eg]: https://github.com/philbooth/complexityReport.js/blob/master/SELF.md | ||
[esprima]: http://esprima.org/ | ||
@@ -205,2 +217,4 @@ [jscomplexity]: http://jscomplexity.org/ | ||
[plato]: https://github.com/jsoverson/plato | ||
[viget]: http://viget.com/ | ||
[grunt-complexity]: https://github.com/vigetlabs/grunt-complexity | ||
[tracker]: https://github.com/philbooth/complexityReport.js/issues | ||
@@ -207,0 +221,0 @@ [node]: http://nodejs.org/ |
@@ -11,2 +11,3 @@ #!/usr/bin/env node | ||
fs = require('fs'), | ||
path = require('path'), | ||
cr = require('./complexityReport'), | ||
@@ -18,4 +19,4 @@ check = require('check-types'), | ||
state = { | ||
reading: true, | ||
unread: 0, | ||
starting: true, | ||
unreadCount: 0, | ||
tooComplex: false | ||
@@ -25,3 +26,3 @@ }; | ||
parseCommandLine(); | ||
readSourceFiles(); | ||
readFiles(cli.args); | ||
@@ -99,3 +100,2 @@ function parseCommandLine () { | ||
if (check.isUnemptyString(cli.format) === false) { | ||
@@ -107,17 +107,30 @@ cli.format = 'plain'; | ||
function readSourceFiles () { | ||
var i; | ||
function readFiles (paths) { | ||
paths.forEach(function (p) { | ||
var stat = fs.statSync(p); | ||
for (i = 0; i < cli.args.length; i += 1) { | ||
state.unread += 1; | ||
readSourceFile(cli.args[i]); | ||
} | ||
if (stat.isDirectory()) { | ||
readDirectory(p); | ||
} else { | ||
readFile(p); | ||
} | ||
}); | ||
state.reading = false; | ||
state.starting = false; | ||
} | ||
function readSourceFile (path) { | ||
fs.readFile(path, 'utf8', function (err, source) { | ||
function readDirectory (directoryPath) { | ||
readFiles( | ||
fs.readdirSync(directoryPath).map(function (p) { | ||
return path.resolve(directoryPath, p); | ||
}) | ||
); | ||
} | ||
function readFile (filePath) { | ||
state.unreadCount += 1; | ||
fs.readFile(filePath, 'utf8', function (err, source) { | ||
if (err) { | ||
error('readSourceFile', err); | ||
error('readFile', err); | ||
} | ||
@@ -129,3 +142,3 @@ | ||
getReport(path, source); | ||
getReport(filePath, source); | ||
@@ -153,3 +166,3 @@ finish(); | ||
function getReport (path, source) { | ||
function getReport (filePath, source) { | ||
var report = cr.run(source, options); | ||
@@ -161,3 +174,3 @@ | ||
report.module = path; | ||
report.module = filePath; | ||
@@ -219,5 +232,5 @@ reports.push(report); | ||
function finish () { | ||
state.unread -= 1; | ||
state.unreadCount -= 1; | ||
if (state.reading === false && state.unread === 0) { | ||
if (state.starting === false && state.unreadCount === 0) { | ||
if (!cli.silent) { | ||
@@ -224,0 +237,0 @@ writeReport(); |
196300
57
3099
220