code-complexity
Version:
Measure the churn/complexity score. Higher values mean hotspots where refactorings should happen.
46 lines (45 loc) • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const sloc_1 = require("./strategies/sloc");
const cyclomatic_1 = require("./strategies/cyclomatic");
const halstead_1 = require("./strategies/halstead");
const node_path_1 = require("node:path");
const utils_1 = require("../../utils");
// FIXME: add modules
class Complexity {
path;
complexity;
static async compute(path, options) {
const complexity = await Complexity.computeComplexity(path, options);
return new Complexity(path, complexity);
}
constructor(path, complexity) {
this.path = path;
this.complexity = complexity;
}
static async computeComplexity(path, options) {
const absolutePath = (0, node_path_1.resolve)(options.directory, path);
let result;
switch (options.complexityStrategy) {
case "sloc":
result = await (0, sloc_1.default)(absolutePath);
break;
case "cyclomatic":
result = await (0, cyclomatic_1.calculate)(absolutePath);
break;
case "halstead":
result = await (0, halstead_1.calculate)(absolutePath);
break;
default:
result = await (0, sloc_1.default)(absolutePath);
}
if (result instanceof utils_1.UnsupportedExtension) {
result = await (0, sloc_1.default)(absolutePath);
}
return result;
}
getValue() {
return this.complexity;
}
}
exports.default = Complexity;