Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Run a simple script which shows the most cyclomatic-complex functions.

  • Loading branch information...
commit 1032a91a5ba3fae8b4816390ad93ab360a8a3be9 1 parent 1ec88c8
@ariya ariya authored
Showing with 23 additions and 1 deletion.
  1. +5 −1 package.json
  2. +18 −0 tools/list-complexity.js
View
6 package.json
@@ -35,7 +35,11 @@
"coverage": "npm run-script analyze-coverage && npm run-script check-coverage",
"analyze-coverage": "node node_modules/istanbul/lib/cli.js cover test/runner.js",
"check-coverage": "node node_modules/istanbul/lib/cli.js check-coverage --statement -5 --branch -17 --function 100",
- "complexity": "node node_modules/complexity-report/src/cli.js --maxcc 30 --silent -l -w esprima.js",
+
+ "complexity": "npm run-script analyze-complexity && npm run-script check-complexity",
+ "analyze-complexity": "node tools/list-complexity.js",
+ "check-complexity": "node node_modules/complexity-report/src/cli.js --maxcc 30 --silent -l -w esprima.js",
+
"benchmark": "node test/benchmarks.js",
"benchmark-quick": "node test/benchmarks.js quick"
}
View
18 tools/list-complexity.js
@@ -0,0 +1,18 @@
+var cr = require('complexity-report'),
+ content = require('fs').readFileSync('esprima.js', 'utf-8'),
+ opt = { logicalor: false, switchcase: false },
+ list = [];
+
+cr.run(content, opt).functions.forEach(function (entry) {
+ var name = (entry.name === '<anonymous>') ? (':' + entry.line) : entry.name;
+ list.push({ name: name, value: entry.complexity.cyclomatic });
+});
+
+list.sort(function (x, y) {
+ return y.value - x.value;
+});
+
+console.log('Most cyclomatic-complex functions:');
+list.slice(0, 6).forEach(function (entry) {
+ console.log(' ', entry.name, entry.value);
+});
Please sign in to comment.
Something went wrong with that request. Please try again.