-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomplexity-runner.js
More file actions
38 lines (32 loc) · 1.12 KB
/
complexity-runner.js
File metadata and controls
38 lines (32 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const MetricsParser = require('tsmetrics-core/MetricsParser').MetricsParser;
const MetricsConfiguration = require('tsmetrics-core/MetricsConfiguration').MetricsConfiguration;
const glob = require('glob');
const path = require('path');
const argv = require('yargs').argv;
const maxComplexity = getMaxComplexity();
let errorFound = false;
module.exports = class ComplexityRunner {
getMetrics(filePath) {
var metricsForFile = MetricsParser.getMetrics(filePath, new MetricsConfiguration(), 1/* ts.ScriptTarget.ES5 */);
return this.log(metricsForFile.metrics, filePath, 0);
}
log(model, file, level) {
let errorFound = false;
if (level > 0 && model.getCollectedComplexity() > maxComplexity) {
console.log(file + ': Complexity:' + model.toLogString('Depth: ' + level + ' -'));
errorFound = true;
}
model.children.forEach(element => {
this.log(element, file, level + 1);
});
return errorFound;
}
}
function getMaxComplexity() {
try {
return parseInt(argv['max-complexity']);
}
catch (e) {
return 15;
}
}