complexity-report
Advanced tools
Comparing version 1.3.1 to 1.4.0
{ | ||
"name": "complexity-report", | ||
"version": "1.3.1", | ||
"description": "Software complexity analysis for JavaScript projects", | ||
"homepage": "https://github.com/philbooth/complexity-report", | ||
"bugs": "https://github.com/philbooth/complexity-report/issues", | ||
"license": "MIT", | ||
"author": "Phil Booth <pmbooth@gmail.com>", | ||
"bin": { | ||
"cr": "./src/index.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/philbooth/complexity-report.git" | ||
}, | ||
"keywords": [ | ||
"complexity", | ||
"simplicity", | ||
"cyclomatic", | ||
"halstead", | ||
"maintainability", | ||
"static", | ||
"analysis", | ||
"metrics", | ||
"escomplex" | ||
], | ||
"dependencies": { | ||
"escomplex-js": "1.1.0", | ||
"escomplex-coffee": "0.2.0", | ||
"escomplex": "1.1.0", | ||
"check-types": "2.1.x", | ||
"commander": "2.0.x" | ||
}, | ||
"devDependencies": { | ||
"jshint": "2.1.x", | ||
"mocha": "1.13.x", | ||
"chai": "1.8.x" | ||
}, | ||
"scripts": { | ||
"lint": "./node_modules/jshint/bin/jshint src --config config/jshint.json", | ||
"test": "./node_modules/mocha/bin/mocha --ui tdd --reporter spec --colors test" | ||
} | ||
"name": "complexity-report", | ||
"version": "1.4.0", | ||
"description": "Software complexity analysis for JavaScript projects", | ||
"homepage": "https://github.com/philbooth/complexity-report", | ||
"bugs": "https://github.com/philbooth/complexity-report/issues", | ||
"license": "MIT", | ||
"author": "Phil Booth <pmbooth@gmail.com>", | ||
"bin": { | ||
"cr": "./src/index.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/philbooth/complexity-report.git" | ||
}, | ||
"keywords": [ | ||
"complexity", | ||
"simplicity", | ||
"cyclomatic", | ||
"halstead", | ||
"maintainability", | ||
"static", | ||
"analysis", | ||
"metrics", | ||
"escomplex" | ||
], | ||
"dependencies": { | ||
"async": "^0.9.0", | ||
"check-types": "2.1.x", | ||
"commander": "2.0.x", | ||
"escomplex": "1.2.x", | ||
"escomplex-coffee": "0.3.x", | ||
"escomplex-js": "1.2.x" | ||
}, | ||
"devDependencies": { | ||
"jshint": "2.1.x", | ||
"mocha": "1.13.x", | ||
"chai": "1.8.x" | ||
}, | ||
"scripts": { | ||
"lint": "./node_modules/jshint/bin/jshint src --config config/jshint.json", | ||
"test": "./node_modules/mocha/bin/mocha --ui tdd --reporter spec --colors test" | ||
} | ||
} | ||
111
src/index.js
#!/usr/bin/env node | ||
/*globals require, process, console, setImmediate */ | ||
/*globals require, process, console */ | ||
'use strict'; | ||
var options, formatter, state, | ||
var options, formatter, state, queue, | ||
@@ -15,19 +15,19 @@ cli = require('commander'), | ||
escomplex = require('escomplex'), | ||
check = require('check-types'); | ||
check = require('check-types'), | ||
async = require('async'); | ||
parseCommandLine(); | ||
state = { | ||
starting: true, | ||
openFileCount: 0, | ||
sources: { | ||
js: [], | ||
coffee: [] | ||
js: [], | ||
coffee: [] | ||
}, | ||
tooComplex: false, | ||
failingModules: [] | ||
}; | ||
expectFiles(cli.args, cli.help.bind(cli)); | ||
readFiles(cli.args); | ||
queue = async.queue(readFile, cli.maxfiles); | ||
processPaths(cli.args, function() { | ||
}); | ||
@@ -64,2 +64,3 @@ function parseCommandLine () { | ||
option('-T, --coffeescript', 'include coffee-script files'). | ||
option('-Q, --nocoresize', 'don\'t calculate core size or visibility matrix'). | ||
parse(process.argv); | ||
@@ -81,3 +82,4 @@ | ||
newmi: cli.newmi || false, | ||
ignoreErrors: cli.ignoreerrors || false | ||
ignoreErrors: cli.ignoreerrors || false, | ||
noCoreSize: cli.nocoresize || false | ||
}; | ||
@@ -91,5 +93,5 @@ | ||
if (cli.coffeescript) { | ||
cli.filepattern = '\\.(js|coffee)$'; | ||
cli.filepattern = '\\.(js|coffee)$'; | ||
} else { | ||
cli.filepattern = '\\.js$'; | ||
cli.filepattern = '\\.js$'; | ||
} | ||
@@ -146,41 +148,48 @@ } | ||
function readFiles (paths) { | ||
paths.forEach(function (p) { | ||
var stat = fs.statSync(p); | ||
function processPaths (paths, cb) { | ||
async.each(paths, processPath, function(err) { | ||
if (err) { | ||
error('readFiles', err); | ||
} | ||
queue.drain = function() { | ||
getReports(); | ||
cb(); | ||
}; | ||
}); | ||
} | ||
function processPath(p, cb) { | ||
fs.stat(p, function(err, stat) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (stat.isDirectory()) { | ||
if ((!cli.dirpattern || cli.dirpattern.test(p)) && (!cli.excludepattern || !cli.excludepattern.test(p))) { | ||
readDirectory(p); | ||
return readDirectory(p, cb); | ||
} | ||
} else if (cli.filepattern.test(p)) { | ||
conditionallyReadFile(p); | ||
queue.push(p); | ||
} | ||
cb(); | ||
}); | ||
state.starting = false; | ||
} | ||
function readDirectory (directoryPath) { | ||
readFiles( | ||
fs.readdirSync(directoryPath).filter(function (p) { | ||
function readDirectory (directoryPath, cb) { | ||
fs.readdir(directoryPath, function(err, files) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
files = files.filter(function (p) { | ||
return path.basename(p).charAt(0) !== '.' || cli.allfiles; | ||
}).map(function (p) { | ||
return path.resolve(directoryPath, p); | ||
}) | ||
); | ||
} | ||
function conditionallyReadFile (filePath) { | ||
if (isOpenFileLimitReached()) { | ||
setImmediate(function () { | ||
conditionallyReadFile(filePath); | ||
}); | ||
} else { | ||
readFile(filePath); | ||
} | ||
if (!files.length) { | ||
return cb(); | ||
} | ||
async.each(files, processPath, cb); | ||
}); | ||
} | ||
function readFile (filePath) { | ||
state.openFileCount += 1; | ||
function readFile(filePath, cb) { | ||
fs.readFile(filePath, 'utf8', function (err, source) { | ||
@@ -191,4 +200,2 @@ if (err) { | ||
state.openFileCount -= 1; | ||
if (beginsWithShebang(source)) { | ||
@@ -199,9 +206,6 @@ source = commentFirstLine(source); | ||
setSource(filePath, source); | ||
cb(); | ||
}); | ||
} | ||
function isOpenFileLimitReached () { | ||
return state.openFileCount >= cli.maxfiles; | ||
} | ||
function error (functionName, err) { | ||
@@ -230,6 +234,2 @@ fail('Fatal error [' + functionName + ']: ' + err.message); | ||
}); | ||
if (state.starting === false && state.openFileCount === 0) { | ||
getReports(); | ||
} | ||
} | ||
@@ -245,6 +245,11 @@ | ||
try { | ||
jsResult = js.analyse(state.sources.js, options); | ||
if (cli.coffeescript) { | ||
// if we have coffeescript, | ||
// we will be merning results | ||
// and recalculating all the values. | ||
// skipping the calculation here saves on computation | ||
options.skipCalculation = true; | ||
coffeeResult = coffee.analyse(state.sources.coffee, options); | ||
} | ||
jsResult = js.analyse(state.sources.js, options); | ||
result = mergeResults(jsResult, coffeeResult); | ||
@@ -271,9 +276,9 @@ | ||
function mergeResults(jsRes, coffeeRes) { | ||
if (!coffeeRes) { | ||
return jsRes; | ||
} | ||
if (!coffeeRes) { | ||
return jsRes; | ||
} | ||
jsRes.reports = jsRes.reports.concat(coffeeRes.reports); | ||
jsRes.reports = jsRes.reports.concat(coffeeRes.reports); | ||
return escomplex.processResults(jsRes); | ||
return escomplex.processResults(jsRes, cli.nocoresize || false); | ||
} | ||
@@ -280,0 +285,0 @@ |
58497
622
6
+ Addedasync@^0.9.0
+ Addedasync@0.9.2(transitive)
+ Addedescomplex@1.2.0(transitive)
+ Addedescomplex-coffee@0.3.0(transitive)
+ Addedescomplex-js@1.2.0(transitive)
- Removedescomplex@1.0.01.1.0(transitive)
- Removedescomplex-coffee@0.2.0(transitive)
- Removedescomplex-js@1.1.0(transitive)
Updatedescomplex@1.2.x
Updatedescomplex-coffee@0.3.x
Updatedescomplex-js@1.2.x