UNPKG

escomplex-plugin-metrics-module

Version:

Provides the core module metric / report generation plugin for typhonjs-escomplex module processing.

91 lines (69 loc) 4.19 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _ObjectUtil = require('typhonjs-escomplex-commons/dist/utils/ObjectUtil'); var _ObjectUtil2 = _interopRequireDefault(_ObjectUtil); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Provides a typhonjs-escomplex-module / ESComplexModule plugin which gathers and calculates all default metrics. * * @see https://www.npmjs.com/package/typhonjs-escomplex-commons * @see https://www.npmjs.com/package/typhonjs-escomplex-module */ var ModuleMetricAverage = function () { function ModuleMetricAverage() { (0, _classCallCheck3.default)(this, ModuleMetricAverage); } (0, _createClass3.default)(ModuleMetricAverage, null, [{ key: 'calculate', /** * Coordinates calculating all metrics. All module and class methods are traversed. If there are no module or class * methods respectively the aggregate MethodReport is used for calculations. * * @param {ModuleReport} moduleReport - The ModuleReport being processed. * @param {object} settings - Settings for module processing. */ value: function calculate(moduleReport) { var moduleMethodCount = moduleReport.methods.length; var moduleAggregateDivisor = moduleMethodCount + 1; // Include the module as a potential control path. // Handle module methods. moduleReport.methods.forEach(function (methodReport) { _ObjectUtil2.default.safeBatchSet(moduleReport.methodAverage, moduleReport.methodAverage.keys, methodReport, 'add'); }); // Handle module class reports. moduleReport.classes.forEach(function (classReport) { var classMethodCount = classReport.methods.length; var classAggregateDivisor = classMethodCount + 1; moduleMethodCount += classMethodCount; moduleAggregateDivisor += classMethodCount; // Soon to add + 1 for the Class aggregate // Process all class methods. classReport.methods.forEach(function (methodReport) { _ObjectUtil2.default.safeBatchSet(moduleReport.methodAverage, classReport.methodAverage.keys, methodReport, 'add'); _ObjectUtil2.default.safeBatchSet(classReport.methodAverage, classReport.methodAverage.keys, methodReport, 'add'); }); // Calculate the pure average method data only if there are class methods. if (classMethodCount !== 0) { _ObjectUtil2.default.safeBatchSet(classReport.methodAverage, classReport.methodAverage.keys, classMethodCount, 'div'); } // Calculate average class aggregate method data by adding the aggregate & dividing by the class divisor. _ObjectUtil2.default.safeBatchSet(classReport.aggregateAverage, classReport.aggregateAverage.keys, classReport.aggregate, 'add'); _ObjectUtil2.default.safeBatchSet(classReport.aggregateAverage, classReport.aggregateAverage.keys, classAggregateDivisor, 'div'); }); // Calculate the pure average method data only if there are module methods. if (moduleMethodCount !== 0) { _ObjectUtil2.default.safeBatchSet(moduleReport.methodAverage, moduleReport.methodAverage.keys, moduleMethodCount, 'div'); } // Calculate average module aggregate method data by adding the aggregate & dividing by the module divisor. _ObjectUtil2.default.safeBatchSet(moduleReport.aggregateAverage, moduleReport.aggregateAverage.keys, moduleReport.aggregate, 'add'); _ObjectUtil2.default.safeBatchSet(moduleReport.aggregateAverage, moduleReport.aggregateAverage.keys, moduleAggregateDivisor, 'div'); } }]); return ModuleMetricAverage; }(); exports.default = ModuleMetricAverage; module.exports = exports['default'];