code-complexity
Version:
Measure the churn/complexity score. Higher values mean hotspots where refactorings should happen.
57 lines (56 loc) • 1.57 kB
JavaScript
;
exports.__esModule = true;
var Table = require("cli-table3");
var utils_1 = require("../utils");
var internal = { debug: (0, utils_1.buildDebugger)("output") };
exports["default"] = {
render: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (0, utils_1.withDuration)(render, args, internal.debug);
}
};
function render(statistics, options) {
var stdout;
switch (options.format) {
case "table":
stdout = toTable(statistics);
break;
case "json":
stdout = toJson(statistics);
break;
case "csv":
stdout = toCSV(statistics);
break;
default:
stdout = toTable(statistics);
}
console.log(stdout);
}
function toJson(statistics) {
return JSON.stringify(statistics.map(function (s) { return s.toState(); }));
}
function toTable(statistics) {
var table = new Table({
head: ["file", "complexity", "churn", "score"]
});
statistics.forEach(function (statistics) {
table.push([
statistics.path,
statistics.complexity,
statistics.churn,
statistics.score,
]);
});
return table.toString();
}
function toCSV(statistics) {
var csv = "file,complexity,churn,score\n";
statistics.forEach(function (stat) {
csv +=
[stat.path, stat.complexity, stat.churn, stat.score].join(",") + "\n";
});
return csv;
}