code-complexity
Version:
Measure the churn/complexity score. Higher values mean hotspots where refactorings should happen.
45 lines (44 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const churn_1 = require("./churn");
// FIXME: add commits
class Churns {
churnByPath;
options;
static from(history, options) {
return new Churns(history, options);
}
constructor(history, options) {
this.options = options;
this.churnByPath = this.computeChurnsPerFiles(history);
}
get files() {
return [...this.churnByPath.keys()];
}
getByPath(path) {
const churn = this.churnByPath.get(path);
if (!churn) {
throw new Error("churn not found for path: " + path);
}
return churn;
}
computeChurnsPerFiles(history) {
return history.reduce((map, path) => {
if (map.has(path)) {
const actualChurn = map.get(path);
if (actualChurn) {
actualChurn.increment();
}
else {
throw new Error("A churn should have existed for path: " + path);
}
}
else {
const churn = new churn_1.default(path).increment();
map.set(path, churn);
}
return map;
}, new Map());
}
}
exports.default = Churns;