complexity-report
Advanced tools
Comparing version 0.6.2 to 0.7.0
{ | ||
"name": "complexity-report", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"author": "Phil Booth <pmbooth@gmail.com>", | ||
"description": "A tool for reporting code complexity metrics in JavaScript projects.", | ||
"contributors": { | ||
"name": "Phil Booth", | ||
"email": "pmbooth@gmail.com" | ||
}, | ||
"contributors": [ | ||
{ "name": "Phil Booth", "email": "pmbooth@gmail.com" }, | ||
{ "name": "Juzer Ali" }, | ||
{ "name": "Mark Trostler" } | ||
], | ||
"bin": { | ||
@@ -37,3 +38,3 @@ "cr": "./src/cli.js" | ||
"jshint": "0.9.x", | ||
"mocha": "1.7.x", | ||
"mocha": "1.8.x", | ||
"chai": "1.4.x" | ||
@@ -40,0 +41,0 @@ }, |
@@ -71,3 +71,4 @@ # complexityReport.js | ||
* `-i`: Treats `for`...`in` loops as a source of cyclomatic complexity. | ||
* `-c`: Treats `catch` clauses as a source of cyclomatic complexity. | ||
* `-t`: Treats `catch` clauses as a source of cyclomatic complexity. | ||
* `-n`: Uses the [Microsoft-variant maintainability index][msvariant]. | ||
@@ -193,2 +194,3 @@ #### Output formats | ||
[jscomplexity]: http://jscomplexity.org/ | ||
[msvariant]: http://blogs.msdn.com/b/codeanalysis/archive/2007/11/20/maintainability-index-range-and-meaning.aspx | ||
[gleb]: https://github.com/bahmutov | ||
@@ -195,0 +197,0 @@ [js-complexity-viz]: https://github.com/bahmutov/js-complexity-viz |
@@ -38,3 +38,3 @@ #!/usr/bin/env node | ||
'-m, --maxmi <maintainability>', | ||
'specifify the per-module maintainability index threshold', | ||
'specify the per-module maintainability index threshold', | ||
parseFloat | ||
@@ -44,10 +44,8 @@ ). | ||
'-c, --maxcc <complexity>', | ||
'specifify the per-function cyclomatic complexity threshold', | ||
function (value) { | ||
return parseInt(value, 10); | ||
} | ||
'specify the per-function cyclomatic complexity threshold', | ||
parseInt | ||
). | ||
option( | ||
'-d, --maxhd <difficulty>', | ||
'specifify the per-function Halstead difficulty threshold', | ||
'specify the per-function Halstead difficulty threshold', | ||
parseFloat | ||
@@ -57,3 +55,3 @@ ). | ||
'-v, --maxhv <volume>', | ||
'specifify the per-function Halstead volume threshold', | ||
'specify the per-function Halstead volume threshold', | ||
parseFloat | ||
@@ -63,3 +61,3 @@ ). | ||
'-e, --maxhe <effort>', | ||
'specifify the per-function Halstead effort threshold', | ||
'specify the per-function Halstead effort threshold', | ||
parseFloat | ||
@@ -84,4 +82,8 @@ ). | ||
option( | ||
'-c, --trycatch', | ||
'-t, --trycatch', | ||
'treat catch clauses as source of cyclomatic complexity' | ||
). | ||
option( | ||
'-n, --newmi', | ||
'use the Microsoft-variant maintainability index (scale of 0 to 100)' | ||
); | ||
@@ -95,5 +97,7 @@ | ||
forin: cli.forin || false, | ||
trycatch: cli.trycatch || false | ||
trycatch: cli.trycatch || false, | ||
newmi: cli.newmi || false | ||
}; | ||
if (check.isUnemptyString(cli.format) === false) { | ||
@@ -100,0 +104,0 @@ cli.format = 'plain'; |
@@ -50,3 +50,3 @@ /** | ||
calculateMetrics(); | ||
calculateMetrics(settings); | ||
@@ -61,3 +61,4 @@ return report; | ||
forin: false, | ||
trycatch: false | ||
trycatch: false, | ||
newmi: false | ||
}; | ||
@@ -265,3 +266,3 @@ } | ||
function calculateMetrics () { | ||
function calculateMetrics (settings) { | ||
var i, data, averages, | ||
@@ -296,3 +297,4 @@ | ||
averages[indices.complexity], | ||
averages[indices.loc] | ||
averages[indices.loc], | ||
settings | ||
); | ||
@@ -333,3 +335,3 @@ } | ||
function calculateMaintainabilityIndex (averageEffort, averageComplexity, averageLoc) { | ||
function calculateMaintainabilityIndex (averageEffort, averageComplexity, averageLoc, settings) { | ||
if (averageComplexity === 0) { | ||
@@ -348,3 +350,7 @@ throw new Error('Encountered function with cyclomatic complexity zero!'); | ||
} | ||
if (settings.newmi) { | ||
report.maintainability = Math.max(0, (report.maintainability*100)/171); | ||
} | ||
} | ||
Sorry, the diff of this file is too big to display
144120
3048
206