ES6 Plato on GitHub
Report Home
Summary Display
plato/src/reporters/complexity/index.ts
Maintainability
66.18
Lines of code
82
Difficulty
18.46
Estimated Errors
0.34
Function weight
By Complexity
By SLOC
"use strict"; //TODO: make this not a janky munge of old plato code and the new stuff import escomplex from "@ponticus/escomplex"; import _ from "lodash"; import { type ComplexityReporterOptions } from "@ponticus/types"; class ComplexityReporter { options: ComplexityReporterOptions; babelOptions: any; constructor(options: ComplexityReporterOptions) { this.options = options; this.babelOptions = options?.parserOptions?.babelOptions; } methodToReportFunction(func) { func.complexity = _.extend( {}, { cyclomatic: func.cyclomatic, sloc: func.sloc, halstead: func.halstead, } ); func.line = func.line || func.lineStart; return func; } allClassMethods(report) { if (!report.classes.length) { return []; } return _.chain(report.classes) .map(function (_class) { return _class.methods; }) .flatten() .value(); } async process(source: string, reportInfo) { const report = await escomplex.analyzeModule( source, this.options, this.babelOptions ); // Make the short filename easily accessible report.module = reportInfo.fileShort; // Munge the new `escomplex-js` format to match the older format of // `complexity-report` //this is just adapting the new module to the old stuff. //TODO its messy and it needs ot not be here forever. /* date: date, sloc: r.aggregate.complexity.sloc.physical, lloc: r.aggregate.complexity.sloc.logical, functions: r.functions.length, deliveredBugs: r.aggregate.complexity.halstead.bugs, maintainability: r.maintainability, difficulty: r.aggregate.complexity.halstead.difficulty */ report.aggregate = report.aggregate || {}; report.aggregate.complexity = _.clone(report.aggregateAverage); let functions = report.methods.concat(this.allClassMethods(report)); report.functions = _.chain(functions) .map(this.methodToReportFunction) .value(); return report; } } export default ComplexityReporter;