CRAP |
Complexity |
Coverage |
Location |
1.00 |
1 |
18/21 (85.71%) |
crap/crap-report.service.ts
(L58 - L119)
|
private async processFile({ fileCoverage }: { fileCoverage: FileCoverageData }): Promise<CrapFile> {
const result: CrapFile = {};
const { fnMap, path: sourcePath } = fileCoverage;
const uncoveredLinesInFile = this.getUncoveredLines(fileCoverage);
const lintReport = await this.complexityService.getComplexity({ sourcePath });
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,
});
});
return result;
}