complexity-report
Advanced tools
Comparing version 0.1.5 to 0.2.0
{ | ||
"name": "complexity-report", | ||
"version": "0.1.5", | ||
"version": "0.2.0", | ||
"author": "Phil Booth <pmbooth@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "A tool for reporting code complexity metrics in JavaScript projects.", |
@@ -83,6 +83,5 @@ /*globals require, process */ | ||
function readSourceFile (path) { | ||
fs.readFile(path, 'utf8', function (error, source) { | ||
if (error) { | ||
console.log('Fatal error: ' + error.message); | ||
process.exit(1); | ||
fs.readFile(path, 'utf8', function (err, source) { | ||
if (err) { | ||
error('readSourceFile', err); | ||
} | ||
@@ -96,2 +95,11 @@ | ||
function error (functionName, err) { | ||
fail('Fatal error [' + functionName + ']: ' + err.message); | ||
} | ||
function fail (message) { | ||
console.log(message); | ||
process.exit(1); | ||
} | ||
function getReport (path, source) { | ||
@@ -137,6 +145,5 @@ var report = cr.run(source); | ||
if (check.isUnemptyString(cli.output)) { | ||
fs.writeFile(cli.output, formatted, 'utf8', function (error) { | ||
if (error) { | ||
console.log('Fatal error: ' + error.message); | ||
process.exit(1); | ||
fs.writeFile(cli.output, formatted, 'utf8', function (err) { | ||
if (err) { | ||
error('writeReport', err); | ||
} | ||
@@ -152,14 +159,9 @@ }); | ||
function exit () { | ||
// TODO: Refactor all the exity stuff | ||
// TODO: Refactor all the loggy stuff | ||
// TODO: Use Q | ||
if (state.tooComplex) { | ||
console.log('Complexity threshold breached'); | ||
process.exit(1); | ||
fail('Warning: Complexity threshold breached!'); | ||
} | ||
console.log('Done'); | ||
} | ||
}()); | ||
@@ -61,5 +61,6 @@ /*globals exports, require */ | ||
function createFunctionReport (name) { | ||
function createFunctionReport (name, lines) { | ||
return { | ||
name: name, | ||
lines: lines, | ||
complexity: { | ||
@@ -166,3 +167,3 @@ cyclomatic: 1 | ||
function processFunctionBody (name, body, report) { | ||
var currentReport = createFunctionReport(name); | ||
var currentReport = createFunctionReport(name, body.loc); | ||
@@ -169,0 +170,0 @@ report.functions.push(currentReport); |
@@ -11,3 +11,3 @@ /*globals exports */ | ||
for (i = 0; i < reports.length; i += 1) { | ||
formatted += formatModule(reports[i]); | ||
formatted += formatModule(reports[i]) + '\n\n'; | ||
} | ||
@@ -20,6 +20,5 @@ | ||
return [ | ||
'\n', | ||
report.module, | ||
'\n\n', | ||
'Aggregate complexity: ', | ||
' Aggregate cyclomatic complexity: ', | ||
report.aggregate.complexity.cyclomatic, | ||
@@ -42,9 +41,7 @@ formatFunctions(report.functions) | ||
return [ | ||
'Function: ', | ||
report.name, | ||
'\n', | ||
'Cyclomatic complexity: ', | ||
report.complexity.cyclomatic | ||
' Function: ', report.name, '\n', | ||
' Lines: ', report.lines.start.line, '-', report.lines.end.line, '\n', | ||
' Cyclomatic complexity: ', report.complexity.cyclomatic | ||
].join(''); | ||
} | ||
43500
1024