CRAP |
Complexity |
Coverage |
Location |
4.13 |
4 |
12/15 (80.00%) |
crap/crap-report.service.ts
(L66 - L116)
|
Object.keys(fnMap).forEach((key) => {
const coverageFunction = fnMap[key];
const lintFunction = this.lintService.getLintFunctionForCoverageFunction({ coverageFunction, lintReport });
if (!lintFunction) {
this.logger.error(`Function '${coverageFunction.name}' not found in ESLint data.`, {
file: fileCoverage.path,
start: coverageFunction.loc.start,
end: coverageFunction.loc.end,
});
return;
}
const coverageData = getCoverageForFunction({
functionId: key,
fileCoverage,
});
const { covered: coveredStatements, total: totalStatements } = coverageData;
const coverage = totalStatements === 0 ? 1 : coveredStatements / totalStatements;
const complexity = lintFunction.complexity;
const crapScore = crap({ complexity, coverage });
/*
* Location of the function is taken from ESLint,
* as it is taken directly from the source code and thus more accurate, especially for TypeScript.
*/
result[coverageFunction.name] = {
complexity,
functionDescriptor: lintFunction.functionName,
start: lintFunction.start,
end: lintFunction.end,
statements: {
...coverageData,
coverage,
crap: crapScore,
},
uncoveredLines: uncoveredLinesInFile.filter(
(line) => line >= lintFunction.start.line && line <= lintFunction.end.line,
),
};
if (lintFunction.sourceCode) {
result[coverageFunction.name].sourceCode = lintFunction.sourceCode;
}
this.logger.debug(`Computed CRAP score for '${lintFunction.functionName}'.`, {
coverage,
complexity,
crapScore,
});
});