Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typhonjs-escomplex-commons

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typhonjs-escomplex-commons - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

dist/module/report/averages/HalsteadAverage.js

1

dist/module/plugin/syntax/AbstractSyntaxLoader.js

@@ -16,3 +16,2 @@ 'use strict';

*/
var AbstractSyntaxLoader = function () {

@@ -19,0 +18,0 @@ function AbstractSyntaxLoader() {

@@ -15,3 +15,2 @@ 'use strict';

*/
var AbstractReport = function () {

@@ -24,3 +23,2 @@ /**

*/
function AbstractReport(methodReport) {

@@ -27,0 +25,0 @@ _classCallCheck(this, AbstractReport);

@@ -17,2 +17,6 @@ 'use strict';

var _MethodAverage = require('./averages/MethodAverage');
var _MethodAverage2 = _interopRequireDefault(_MethodAverage);
var _MethodReport = require('./MethodReport');

@@ -35,3 +39,2 @@

*/
var ClassReport = function (_AbstractReport) {

@@ -47,3 +50,2 @@ _inherits(ClassReport, _AbstractReport);

*/
function ClassReport() {

@@ -60,3 +62,2 @@ var name = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0];

*/
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ClassReport).call(this, new _MethodReport2.default('', lineStart, lineEnd, 0)));

@@ -85,2 +86,8 @@

/**
* Stores the average method metric data.
* @type {HalsteadAverage}
*/
_this.methodAverage = new _MethodAverage2.default();
/**
* The name of the class.

@@ -87,0 +94,0 @@ * @type {string}

@@ -15,3 +15,2 @@ 'use strict';

*/
var HalsteadData = function () {

@@ -21,3 +20,2 @@ /**

*/
function HalsteadData() {

@@ -24,0 +22,0 @@ _classCallCheck(this, HalsteadData);

@@ -34,3 +34,2 @@ 'use strict';

*/
var MethodReport = function (_AbstractReport) {

@@ -47,3 +46,2 @@ _inherits(MethodReport, _AbstractReport);

*/
function MethodReport() {

@@ -61,3 +59,2 @@ var name = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0];

*/
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(MethodReport).call(this));

@@ -127,55 +124,2 @@

/**
* Provides a default array and indices for summing maintainability metrics.
*
* @returns {{sums: number[], indices: {cyclomatic: number, effort: number, loc: number, params: number}}}
*/
}, {
key: 'sumMetrics',
/**
* Provides a convenience method to increment metric sums given an object hash of indices.
*
* @param {Array<number>} sums - Running sums for metric calculation.
* @param {object} indices - Indices into the sums array for specific metrics.
*/
value: function sumMetrics(sums, indices) {
/* istanbul ignore if */
if (!Array.isArray(sums)) {
throw new TypeError('sumMetrics error: `sums` is not an `array`.');
}
/* istanbul ignore if */
if ((typeof indices === 'undefined' ? 'undefined' : _typeof(indices)) !== 'object') {
throw new TypeError('sumMetrics error: `indices` is not an `object`.');
}
for (var key in indices) {
switch (key) {
case 'cyclomatic':
sums[indices[key]] += this.cyclomatic;
break;
case 'effort':
sums[indices[key]] += this.halstead.effort;
break;
case 'loc':
sums[indices[key]] += this.sloc.logical;
break;
case 'params':
sums[indices[key]] += this.params;
break;
}
}
}
}], [{
key: 'getMaintainabilityMetrics',
value: function getMaintainabilityMetrics() {
return { sums: [0, 0, 0, 0], indices: s_INDICES_MAINTAINABILITY };
}
/**
* Deserializes a JSON object representing a MethodReport.

@@ -188,3 +132,3 @@ *

}, {
}], [{
key: 'parse',

@@ -204,16 +148,3 @@ value: function parse(object) {

/**
* Defines the default maintainability metrics supported by `sumMetrics`.
* @type {{cyclomatic: number, effort: number, loc: number, params: number}}
* @ignore
*/
exports.default = MethodReport;
var s_INDICES_MAINTAINABILITY = {
cyclomatic: 0,
effort: 1,
loc: 2,
params: 3
};
module.exports = exports['default'];

@@ -21,2 +21,6 @@ 'use strict';

var _MethodAverage = require('./averages/MethodAverage');
var _MethodAverage2 = _interopRequireDefault(_MethodAverage);
var _MethodReport = require('./MethodReport');

@@ -50,3 +54,2 @@

*/
var ModuleReport = function (_AbstractReport) {

@@ -64,3 +67,2 @@ _inherits(ModuleReport, _AbstractReport);

*/
function ModuleReport() {

@@ -77,3 +79,2 @@ var lineStart = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];

*/
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ModuleReport).call(this, new _MethodReport2.default('', lineStart, lineEnd, 0)));

@@ -96,8 +97,2 @@

/**
* Measures the average method cyclomatic complexity of the module / file.
* @type {number}
*/
_this.cyclomatic = 0;
/**
* Stores all parsed dependencies.

@@ -109,8 +104,2 @@ * @type {Array}

/**
* Measures the average method maintenance effort of the module / file.
* @type {number}
*/
_this.effort = 0;
/**
* Stores the file path of the module / file. The file path is only defined as supplied when processing projects.

@@ -134,8 +123,2 @@ * @type {string}

/**
* Measures the average method logical SLOC (source lines of code) for the module / file.
* @type {number}
*/
_this.loc = 0;
/**
* Measures the average method maintainability index for the module / file.

@@ -153,6 +136,6 @@ * @type {number}

/**
* Measures the average number of method parameters for the module / file.
* @type {number}
* Stores the average method metric data.
* @type {MethodAverage}
*/
_this.params = 0;
_this.methodAverage = new _MethodAverage2.default();

@@ -485,29 +468,2 @@ /**

/**
* Provides a convenience method to increment metric sums given an object hash of indices.
*
* @param {Array<number>} sums - Running sums for metric calculation.
* @param {object} indices - Indices into the sums array for specific metrics.
*/
}, {
key: 'sumMetrics',
value: function sumMetrics(sums) {
var indices = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
/* istanbul ignore if */
if (!Array.isArray(sums)) {
throw new TypeError('sumMetrics error: `sums` is not an `array`.');
}
/* istanbul ignore if */
if ((typeof indices === 'undefined' ? 'undefined' : _typeof(indices)) !== 'object') {
throw new TypeError('sumMetrics error: `indices` is not an `object`.');
}
for (var key in indices) {
sums[indices[key]] += typeof this[key] === 'number' ? this[key] : 0;
}
}
/**
* Formats this ModuleReport given the type.

@@ -558,15 +514,3 @@ *

}
/**
* Provides a default array and indices for summing maintainability metrics via `sumMetrics`.
*
* @returns {{sums: number[], indices: {cyclomatic: number, effort: number, loc: number, maintainability: number, params: number}}}
*/
}, {
key: 'getMaintainabilityMetrics',
value: function getMaintainabilityMetrics() {
return { sums: [0, 0, 0, 0, 0], indices: s_INDICES_MAINTAINABILITY };
}
}, {
key: 'parse',

@@ -603,17 +547,3 @@ value: function parse(object) {

/**
* Defines the default maintainability metrics supported by `sumMetrics`.
* @type {{cyclomatic: number, effort: number, loc: number, maintainability: number, params: number}}
* @ignore
*/
exports.default = ModuleReport;
var s_INDICES_MAINTAINABILITY = {
cyclomatic: 0,
effort: 1,
loc: 2,
maintainability: 3,
params: 4
};
module.exports = exports['default'];

@@ -25,3 +25,2 @@ 'use strict';

*/
var HalsteadArray = function () {

@@ -34,3 +33,2 @@ /**

*/
function HalsteadArray(metric, data) {

@@ -126,7 +124,7 @@ _classCallCheck(this, HalsteadArray);

// Map all TraitHalstead data and flatten any array of identifiers returned from `valueOf` and finally convert
// all flattened identifiers to strings as necessary.
// all flattened identifier entries to strings as necessary.
return (_ref = []).concat.apply(_ref, _toConsumableArray(filtered.map(function (traitHalstead) {
return traitHalstead.valueOf.apply(traitHalstead, params);
}))).map(function (entry) {
// Convert any undefined entry to a text string. This should only be possible when a TraitHalstead defined
// Convert any `undefined` entry to a text string. This should only occur when a TraitHalstead defined
// as a function returns an array containing `undefined`; in this case there is an issue with a syntax trait

@@ -141,2 +139,3 @@ // definition not properly verifying data.

// Convert any entries to strings as necessary.
return typeof entry !== 'string' ? JSON.stringify(entry) : entry;

@@ -143,0 +142,0 @@ });

@@ -16,3 +16,2 @@ 'use strict';

*/
var Trait = function () {

@@ -25,3 +24,2 @@ /**

*/
function Trait(metric, data) {

@@ -28,0 +26,0 @@ _classCallCheck(this, Trait);

@@ -17,3 +17,2 @@ 'use strict';

*/
var TraitHalstead = function () {

@@ -26,3 +25,2 @@ /**

*/
function TraitHalstead(metric, data) {

@@ -29,0 +27,0 @@ _classCallCheck(this, TraitHalstead);

@@ -15,2 +15,6 @@ 'use strict';

var _ModuleAverage = require('../../module/report/averages/ModuleAverage');
var _ModuleAverage2 = _interopRequireDefault(_ModuleAverage);
var _ModuleReport = require('../../module/report/ModuleReport');

@@ -39,3 +43,2 @@

*/
var ProjectResult = function () {

@@ -50,3 +53,2 @@ /**

*/
function ProjectResult() {

@@ -88,14 +90,2 @@ var moduleReports = arguments.length <= 0 || arguments[0] === undefined ? void 0 : arguments[0];

/**
* Measures the average method cyclomatic complexity for the project.
* @type {number}
*/
this.cyclomatic = 0;
/**
* Measures the average method maintenance effort for the project.
* @type {number}
*/
this.effort = 0;
/**
* Measures the percentage of all possible internal dependencies that are actually realized in the project.

@@ -108,20 +98,8 @@ * Lower is better.

/**
* Measures the average method logical SLOC (source lines of code) for the project.
* @type {number}
* Stores the average module metric data.
* @type {ModuleAverage}
*/
this.loc = 0;
this.moduleAverage = new _ModuleAverage2.default();
/**
* Measures the average method maintainability index for the project.
* @type {number}
*/
this.maintainability = 0;
/**
* Measures the average number of method parameters for the project.
* @type {number}
*/
this.params = 0;
/**
* Stores all ModuleReport data for the project sorted by the module / files `srcPath`.

@@ -148,4 +126,6 @@ * @type {Array<ModuleReport>}

*
* @param {boolean} serializeReports - (Optional) Allows overriding of ModuleReport serialization;
* default: undefined.
* @param {object} options - (Optional) Allows overriding of ModuleReport serialization.
* @property {boolean} serializeAverages - If serializeReports is false and serializeAverages is true then module
* averages will also be added to a reduced project result; default: false.
* @property {boolean} serializeReports - Allows overriding of ModuleReport serialization; default: true.
*

@@ -159,12 +139,20 @@ * @returns {ProjectResult}

value: function finalize() {
var serializeReports = arguments.length <= 0 || arguments[0] === undefined ? void 0 : arguments[0];
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var serialize = this.getSetting('serializeReports');
if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') {
throw new TypeError('finalize error: \'options\' is not an \'object\'.');
}
var serializeReports = this.getSetting('serializeReports', true);
var serializeAverages = this.getSetting('serializeAverages', false);
// Allow an override opportunity.
if (typeof serializeReports === 'boolean') {
serialize = serializeReports;
if (typeof options.serializeAverages === 'boolean') {
serializeAverages = options.serializeAverages;
}
if (typeof options.serializeReports === 'boolean') {
serializeReports = options.serializeReports;
}
if (serialize) {
if (serializeReports) {
this.reports.forEach(function (report) {

@@ -175,3 +163,11 @@ report.finalize();

this.reports = this.reports.map(function (report) {
return { filePath: report.filePath, srcPath: report.srcPath, srcPathAlias: report.srcPathAlias };
var modReport = { filePath: report.filePath, srcPath: report.srcPath, srcPathAlias: report.srcPathAlias };
// Potentially add module averages
if (serializeAverages) {
modReport.maintainability = report.maintainability;
modReport.methodAverage = report.methodAverage;
}
return modReport;
});

@@ -178,0 +174,0 @@ }

@@ -16,3 +16,2 @@ 'use strict';

*/
var FormatJSON = function () {

@@ -93,3 +92,3 @@ function FormatJSON() {

get: function get() {
return 'json';
return 'full';
}

@@ -96,0 +95,0 @@ }]);

@@ -20,24 +20,2 @@ 'use strict';

/**
* Defines default thresholds for severity levels.
* error levels: info, warning, error
*
* entry: error, line, severity, message, source
*
* @type {{methodReport: object}}
* @ignore
*/
var s_DEFAULT_THRESHOLDS = {
classReport: {
maintainability: { _test: '<', info: 115, warning: 100, error: 90 }
},
methodReport: {
'cyclomatic': { info: 3, warning: 7, error: 12 },
'halstead.difficulty': { info: 8, warning: 13, error: 20 }
},
moduleReport: {
maintainability: { _test: '<', info: 115, warning: 100, error: 90 }
}
};
/**
* Provides a format transform for ESComplex ModuleReport / ProjectResult instances converting them to JSON that

@@ -56,3 +34,2 @@ * corresponds to the XML checkstyle format.

*/
var FormatJSONCheckstyle = function () {

@@ -145,5 +122,3 @@ function FormatJSONCheckstyle() {

*
* @param {object} options - (Optional) One or more optional parameters passed to the formatter.
* @property {{info: number, warning: number, error: number}} cyclomatic - A hash of name / number thresholds.
* @property {{info: number, warning: number, error: number}} halstead - A hash of name / number thresholds.
* @param {object} options - (Optional) One or more optional entries defining threshold parameters.
*

@@ -294,3 +269,31 @@ * @returns {object}

// Module private ---------------------------------------------------------------------------------------------------
/**
* Defines default thresholds for severity levels matching the XML checkstyle format.
* error levels: info, warning, error
*
* Entries may include `classReport`, `methodReport`, `moduleReport` that each define an object hash of threshold
* object hashes. The key of each threshold hash is the entry key to compare against the `info, warning, error` values.
* By default the order flows left to right using greater than comparisons. An optional entry is `_test` which is a
* string defining the comparison operations with the following supported options, `<`, `<=`, `>`, and `>=`.
*
* @type {{classReport: {maintainability: {_test: string, info: number, warning: number, error: number}}, methodReport: {cyclomatic: {info: number, warning: number, error: number}, [halstead.difficulty]: {info: number, warning: number, error: number}}, moduleReport: {maintainability: {_test: string, info: number, warning: number, error: number}}}}
* @ignore
*/
exports.default = FormatJSONCheckstyle;
var s_DEFAULT_THRESHOLDS = {
classReport: {
maintainability: { _test: '<', info: 115, warning: 100, error: 90 }
},
methodReport: {
'cyclomatic': { info: 3, warning: 7, error: 12 },
'halstead.difficulty': { info: 8, warning: 13, error: 20 }
},
moduleReport: {
maintainability: { _test: '<', info: 115, warning: 100, error: 90 }
}
};
module.exports = exports['default'];

@@ -20,17 +20,5 @@ 'use strict';

/**
* Defines the default keys to include in a minimal JSON representation of module / project results.
* @type {{classReport: string[], methodReport: string[], moduleReport: string[]}}
* @ignore
*/
var s_DEFAULT_KEYS = {
classReport: ['maintainability'],
methodReport: ['cyclomatic', 'halstead.difficulty'],
moduleReport: ['maintainability']
};
/**
* Provides a format transform for ESComplex ModuleReport / ProjectResult instances converting them to JSON with
* minimal metrics.
*/
var FormatJSONMinimal = function () {

@@ -293,3 +281,17 @@ function FormatJSONMinimal() {

// Module private ---------------------------------------------------------------------------------------------------
/**
* Defines the default keys to include in a minimal JSON representation of module / project results.
* @type {{classReport: string[], methodReport: string[], moduleReport: string[]}}
* @ignore
*/
exports.default = FormatJSONMinimal;
var s_DEFAULT_KEYS = {
classReport: ['maintainability'],
methodReport: ['cyclomatic', 'halstead.difficulty'],
moduleReport: ['maintainability']
};
module.exports = exports['default'];

@@ -17,3 +17,2 @@ 'use strict';

*/
var FormatJSONModules = function () {

@@ -20,0 +19,0 @@ function FormatJSONModules() {

@@ -28,3 +28,2 @@ 'use strict';

*/
var FormatMarkdown = function (_FormatText) {

@@ -68,14 +67,2 @@ _inherits(FormatMarkdown, _FormatText);

}
/**
* Gets the format type.
*
* @returns {string}
*/
}, {
key: 'type',
get: function get() {
return 'markdown';
}
}]);

@@ -88,3 +75,4 @@

* Defines the default headers as text which are inserted via spread into `StringUtil.safeStringsObject`.
* @type {{classMethod: *[], classReport: *[], moduleMethod: *[], moduleReport: *[]}}
* @type {{classMethod: *[], classReport: *[], entryPrepend: string, moduleMethod: *[], moduleReport: *[], projectResult: string[]}}
* @ignore
*/

@@ -91,0 +79,0 @@

@@ -22,5 +22,4 @@ 'use strict';

/**
* Provides a format transform for ModuleReport / ProjectResult instances converting a matrix list into plain text.
* Provides a format transform for ModuleReport / ProjectResult instances converting a matrix list into markdown.
*/
var FormatMarkdownAdjacency = function (_FormatTextAdjacency) {

@@ -71,3 +70,3 @@ _inherits(FormatMarkdownAdjacency, _FormatTextAdjacency);

* Defines the default headers added to any output strings..
* @type {{entryPrepend: string, textHeader: string}}
* @type {{entryPrepend: string, entryWrapper: string, textHeader: string}}
* @ignore

@@ -74,0 +73,0 @@ */

@@ -29,3 +29,2 @@ 'use strict';

*/
var FormatMarkdownMinimal = function (_FormatTextMinimal) {

@@ -76,3 +75,4 @@ _inherits(FormatMarkdownMinimal, _FormatTextMinimal);

* Defines the default headers as markdown which are inserted via spread into `StringUtil.safeStringsObject`.
* @type {{classMethod: *[], classReport: *[], moduleMethod: *[], moduleReport: *[]}}
* @type {{classMethod: *[], classReport: *[], entryPrepend: string, moduleMethod: *[], moduleReport: *[], projectResult: string[]}}
* @ignore
*/

@@ -79,0 +79,0 @@

@@ -9,5 +9,5 @@ 'use strict';

var _AbstractFormatText2 = require('../text/AbstractFormatText');
var _FormatTextModules2 = require('../text/FormatTextModules');
var _AbstractFormatText3 = _interopRequireDefault(_AbstractFormatText2);
var _FormatTextModules3 = _interopRequireDefault(_FormatTextModules2);

@@ -25,6 +25,5 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

*/
var FormatMarkdownModules = function (_FormatTextModules) {
_inherits(FormatMarkdownModules, _FormatTextModules);
var FormatMarkdownModules = function (_AbstractFormatText) {
_inherits(FormatMarkdownModules, _AbstractFormatText);
function FormatMarkdownModules() {

@@ -63,18 +62,6 @@ var headers = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

}
/**
* Gets the format type.
*
* @returns {string}
*/
}, {
key: 'type',
get: function get() {
return 'modules';
}
}]);
return FormatMarkdownModules;
}(_AbstractFormatText3.default);
}(_FormatTextModules3.default);

@@ -85,3 +72,3 @@ // Module private ---------------------------------------------------------------------------------------------------

* Defines markdown headers as text which are inserted via spread into `StringUtil.safeStringsObject`.
* @type {{classMethod: *[], classReport: *[], moduleMethod: *[], moduleReport: *[]}}
* @type {{moduleReport: string[]}}
* @ignore

@@ -88,0 +75,0 @@ */

@@ -22,5 +22,4 @@ 'use strict';

/**
* Provides a format transform for ModuleReport / ProjectResult instances converting a matrix list into plain text.
* Provides a format transform for ModuleReport / ProjectResult instances converting a matrix list into markdown.
*/
var FormatMarkdownVisibility = function (_FormatTextVisibility) {

@@ -71,3 +70,3 @@ _inherits(FormatMarkdownVisibility, _FormatTextVisibility);

* Defines the default headers added to any output strings..
* @type {{entryPrepend: string, textHeader: string}}
* @type {{entryPrepend: string, entryWrapper: string, textHeader: string}}
* @ignore

@@ -74,0 +73,0 @@ */

@@ -22,4 +22,10 @@ 'use strict';

*/
var AbstractFormatText = function () {
/**
* Initializes instance storing default headers / keys.
*
* @param {object} headers - An object hash of header entries formatted for `StringUtil.safeStringsObject`.
*
* @param {object} keys - An object hash of key entries formatted for `StringUtil.safeStringsObject`.
*/
function AbstractFormatText() {

@@ -129,2 +135,3 @@ var headers = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

* @returns {string}
* @private
*/

@@ -160,2 +167,3 @@

* @returns {string}
* @private
*/

@@ -189,2 +197,3 @@

* @returns {string}
* @private
*/

@@ -235,2 +244,3 @@

* @returns {string}
* @private
*/

@@ -267,2 +277,3 @@

* @returns {string}
* @private
*/

@@ -295,7 +306,8 @@

* @param {object} options - (Optional) One or more optional parameters passed to the formatter.
* @property {string} classReport - An entry key found in the ClassReport to output.
* @property {string} methodReport - An entry key found in the MethodReport to output.
* @property {string} moduleReport - An entry key found in the ModuleReport to output.
* @property {string} classReport - Entry keys found in the ClassReport to output.
* @property {string} methodReport - Entry keys found in the MethodReport to output.
* @property {string} moduleReport - Entry keys found in the ModuleReport to output.
*
* @returns {string}
* @private
*/

@@ -319,2 +331,15 @@

}
/**
* Formats a project result.
*
* @param {ProjectResult} projectResult - A project result.
*
* @param {object} options - (Optional) One or more optional parameters passed to the formatter.
* @property {string} projectResult - Entry keys found in the ProjectReport to output.
*
* @returns {string}
* @private
*/
}, {

@@ -321,0 +346,0 @@ key: '_formatProject',

@@ -20,4 +20,16 @@ 'use strict';

*/
var AbstractTextMatrix = function () {
/**
* Initializes instance storing default headers / keys.
*
* @param {object} headers - An object hash containing the following entries.
* @property {string} entryPrepend - A string to prepend all entries.
* @property {string} entryWrapper - A string to wrap output entries between.
* @property {string} textHeader - A string to prepend output providing a leading header.
*
* @param {object} keys - An object hash containing the following entries.
* @property {boolean} matrixFilePath - If true the module `filePath` is serialized.
* @property {string} matrixList - An entry key to lookup a given matrix list in a ProjectResult.
* @property {boolean} zeroIndex - If true module report indexes are zero indexed.
*/
function AbstractTextMatrix() {

@@ -52,4 +64,6 @@ var headers = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

*
* @param {object} options - (Optional) One or more optional parameters passed to the formatter.
* @property {string} matrixKey - An entry key found in the ProjectResult to output.
* @param {object} options - (Optional) An object hash containing the following entries.
* @property {boolean} matrixFilePath - If true the module `filePath` is serialized.
* @property {string} matrixList - An entry key to lookup a given matrix list in a ProjectResult.
* @property {boolean} zeroIndex - If true module report indexes are zero indexed.
*

@@ -110,4 +124,4 @@ * @returns {string}

* @param {object} options - (Optional) An object hash of options.
* @propert {boolean} zeroIndex - If true module report indexes are zero indexed.
* @propert {boolean} matrixFilePath - If true the module `filePath` is serialized.
* @property {boolean} zeroIndex - If true module report indexes are zero indexed.
* @property {boolean} matrixFilePath - If true the module `filePath` is serialized.
*

@@ -130,6 +144,6 @@ * @returns {string}

matrixList.forEach(function (entry) {
output += '' + entryPrepend + (entry.row + plus1) + ':\t' + entryWrapper + _ObjectUtil2.default.safeAccess(result.reports[entry.row], path) + entryWrapper + '\n';
output += '' + entryPrepend + (entry.row + plus1) + ':\t' + entryWrapper + _ObjectUtil2.default.safeAccess(result.reports[entry.row], path, 'unknown') + entryWrapper + '\n';
entry.cols.forEach(function (colIndex) {
output += '\t' + entryPrepend + (colIndex + plus1) + ':\t' + entryWrapper + _ObjectUtil2.default.safeAccess(result.reports[colIndex], path) + entryWrapper + '\n';
output += '\t' + entryPrepend + (colIndex + plus1) + ':\t' + entryWrapper + _ObjectUtil2.default.safeAccess(result.reports[colIndex], path, 'unknown') + entryWrapper + '\n';
});

@@ -136,0 +150,0 @@

@@ -30,3 +30,2 @@ 'use strict';

*/
var FormatText = function (_AbstractFormatText) {

@@ -123,3 +122,3 @@ _inherits(FormatText, _AbstractFormatText);

get: function get() {
return 'text';
return 'full';
}

@@ -134,18 +133,21 @@ }]);

exports.default = FormatText;
var s_SHARED_DATA = [['Line start: ', 'lineStart'], ['Line end: ', 'lineEnd'], ['Physical LOC: ', 'sloc.physical'], ['Logical LOC: ', 'sloc.logical'], ['Cyclomatic complexity: ', 'cyclomatic'], ['Cyclomatic complexity density: ', 'cyclomaticDensity', 1, '%'], ['Halstead difficulty: ', 'halstead.difficulty'], ['Halstead volume: ', 'halstead.volume'], ['Halstead effort: ', 'halstead.effort']];
var s_SHARED_METHOD_DATA = [['Line start: ', 'lineStart'], ['Line end: ', 'lineEnd'], ['Physical LOC: ', 'sloc.physical'], ['Logical LOC: ', 'sloc.logical'], ['Cyclomatic complexity: ', 'cyclomatic'], ['Cyclomatic complexity density: ', 'cyclomaticDensity', 1, '%'], ['Halstead difficulty: ', 'halstead.difficulty'], ['Halstead volume: ', 'halstead.volume'], ['Halstead effort: ', 'halstead.effort'], ['Parameter count: ', 'params']];
var s_SHARED_METHOD_AVERAGE_DATA = [['Average per-function physical LOC: ', 'methodAverage.sloc.physical'], ['Average per-function logical LOC: ', 'methodAverage.sloc.logical'], ['Average per-function cyclomatic complexity: ', 'methodAverage.cyclomatic'], ['Average per-function cyclomatic density: ', 'methodAverage.cyclomaticDensity', 1, '%'], ['Average per-function halstead difficulty: ', 'methodAverage.halstead.difficulty'], ['Average per-function halstead volume: ', 'methodAverage.halstead.volume'], ['Average per-function halstead effort: ', 'methodAverage.halstead.effort']];
/**
* Defines the default headers as text which are inserted via spread into `StringUtil.safeStringsObject`.
* @type {{classMethod: *[], classReport: *[], moduleMethod: *[], moduleReport: *[]}}
* @type {{classMethod: Array, classReport: Array, methodReport: *[], moduleReport: *[], projectResult: *[]}}
* @ignore
*/
var s_DEFAULT_KEYS = {
classMethod: [].concat(s_SHARED_DATA),
classMethod: [].concat(s_SHARED_METHOD_DATA),
classReport: [].concat(s_SHARED_DATA),
classReport: [['Line start: ', 'lineStart'], ['Line end: ', 'lineEnd']].concat(s_SHARED_METHOD_AVERAGE_DATA),
methodReport: [].concat(s_SHARED_DATA, [['Parameter count: ', 'params']]),
methodReport: [].concat(s_SHARED_METHOD_DATA),
moduleReport: [].concat(s_SHARED_DATA, [['Maintainability index: ', 'maintainability'], ['Dependency count: ', 'dependencies.length']]),
moduleReport: [['Total lines: ', 'lineEnd'], ['Maintainability index: ', 'maintainability'], ['Dependency count: ', 'dependencies.length']].concat(s_SHARED_METHOD_AVERAGE_DATA),
projectResult: [['Mean per-function logical LOC: ', 'loc'], ['Mean per-function parameter count: ', 'params'], ['Mean per-function cyclomatic complexity: ', 'cyclomatic'], ['Mean per-function Halstead effort: ', 'effort'], ['Mean per-module maintainability index: ', 'maintainability'], ['First-order density: ', 'firstOrderDensity', 1, '%'], ['Change cost: ', 'changeCost', 1, '%'], ['Core size: ', 'coreSize', 1, '%']]
projectResult: [['First-order density: ', 'firstOrderDensity', 1, '%'], ['Change cost: ', 'changeCost', 1, '%'], ['Core size: ', 'coreSize', 1, '%'], ['Average per-module maintainability index: ', 'moduleAverage.maintainability'], ['Average per-function physical LOC: ', 'moduleAverage.methodAverage.sloc.physical'], ['Average per-function logical LOC: ', 'moduleAverage.methodAverage.sloc.logical'], ['Average per-function parameter count: ', 'moduleAverage.methodAverage.params'], ['Average per-function cyclomatic complexity: ', 'moduleAverage.methodAverage.cyclomatic'], ['Average per-function halstead difficulty: ', 'moduleAverage.methodAverage.halstead.difficulty'], ['Average per-function halstead effort: ', 'moduleAverage.methodAverage.halstead.effort']]
};

@@ -156,2 +158,3 @@

* @type {{classMethod: *[], classReport: *[], entryPrepend: string, moduleMethod: *[], moduleReport: string[], projectResult: string[]}}
* @ignore
*/

@@ -158,0 +161,0 @@ var s_DEFAULT_HEADERS = {

@@ -24,3 +24,2 @@ 'use strict';

*/
var FormatTextAdjacency = function (_AbstractTextMatrix) {

@@ -95,3 +94,3 @@ _inherits(FormatTextAdjacency, _AbstractTextMatrix);

* Defines the default headers added to any output strings..
* @type {{entryPrepend: string, textHeader: string}}
* @type {{entryPrepend: string, entryWrapper: string, textHeader: string}}
* @ignore

@@ -98,0 +97,0 @@ */

@@ -25,3 +25,2 @@ 'use strict';

*/
var FormatTextMinimal = function (_AbstractFormatTest) {

@@ -84,3 +83,3 @@ _inherits(FormatTextMinimal, _AbstractFormatTest);

* Defines the default keys to include in a minimal text representation of module / project results.
* @type {{classReport: string[], methodReport: string[], moduleReport: string[]}}
* @type {{classReport: string[], methodReport: string[], moduleReport: string[], projectResult: string[]}}
* @ignore

@@ -95,3 +94,3 @@ */

moduleReport: ['maintainability'],
projectResult: ['maintainability']
projectResult: ['moduleAverage.maintainability']
};

@@ -101,3 +100,4 @@

* Defines the default headers as text which are inserted via spread into `StringUtil.safeStringsObject`.
* @type {{classMethod: *[], classReport: *[], moduleMethod: *[], moduleReport: *[]}}
* @type {{classMethod: *[], classReport: *[], entryPrepend: string, moduleMethod: *[], moduleReport: *[], projectResult: string[]}}
* @ignore
*/

@@ -104,0 +104,0 @@ var s_DEFAULT_HEADERS = {

@@ -25,3 +25,2 @@ 'use strict';

*/
var FormatTextModules = function (_AbstractFormatTest) {

@@ -83,4 +82,5 @@ _inherits(FormatTextModules, _AbstractFormatTest);

/**
*
* Defines markdown headers as text which are inserted via spread into `StringUtil.safeStringsObject`.
* @type {{moduleReport: *[]}}
* @ignore
*/

@@ -87,0 +87,0 @@

@@ -24,3 +24,2 @@ 'use strict';

*/
var FormatTextVisibility = function (_AbstractTextMatrix) {

@@ -95,3 +94,3 @@ _inherits(FormatTextVisibility, _AbstractTextMatrix);

* Defines the default headers added to any output strings..
* @type {{entryPrepend: string, textHeader: string}}
* @type {{entryPrepend: string, entryWrapper: string, textHeader: string}}
* @ignore

@@ -98,0 +97,0 @@ */

@@ -20,3 +20,2 @@ 'use strict';

*/
var MathUtil = function () {

@@ -23,0 +22,0 @@ function MathUtil() {

@@ -16,3 +16,2 @@ 'use strict';

*/
var ObjectUtil = function () {

@@ -50,2 +49,20 @@ function ObjectUtil() {

/**
* Returns a list of accessor keys by traversing the given object.
*
* @param {object} data - An object to traverse for accessor keys.
*
* @returns {Array}
*/
}, {
key: 'getAccessorList',
value: function getAccessorList(data) {
if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) !== 'object') {
throw new TypeError('getAccessorList error: \'data\' is not an \'object\'.');
}
return _getAccessorList(data);
}
/**
* Provides a way to safely access an objects data / entries given an accessor string which describes the

@@ -55,3 +72,3 @@ * entries to walk. To access deeper entries into the object format the accessor string with `.` between entries

*
* @param {object} object - An object to access entry data.
* @param {object} data - An object to access entry data.
* @param {string} accessor - A string describing the entries to access.

@@ -65,6 +82,6 @@ * @param {*} defaultValue - (Optional) A default value to return if an entry for accessor is not found.

key: 'safeAccess',
value: function safeAccess(object, accessor) {
value: function safeAccess(data, accessor) {
var defaultValue = arguments.length <= 2 || arguments[2] === undefined ? undefined : arguments[2];
if ((typeof object === 'undefined' ? 'undefined' : _typeof(object)) !== 'object') {
if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) !== 'object') {
return defaultValue;

@@ -81,11 +98,81 @@ }

// If the next level of object access is undefined or null then return the empty string.
if (typeof object[access[cntr]] === 'undefined' || object[access[cntr]] === null) {
if (typeof data[access[cntr]] === 'undefined' || data[access[cntr]] === null) {
return defaultValue;
}
object = object[access[cntr]];
data = data[access[cntr]];
}
return object;
return data;
}
/**
* Provides a way to safely set an objects data / entries given an accessor string which describes the
* entries to walk. To access deeper entries into the object format the accessor string with `.` between entries
* to walk.
*
* @param {object} data - An object to access entry data.
* @param {string} accessor - A string describing the entries to access.
* @param {*} value - A new value to set if an entry for accessor is found.
* @param {string} operation - (Optional) Operation to perform including: 'add', 'div', 'mult', 'set', 'sub';
* default (`set`).
*
* @returns {boolean} True if successful.
*/
}, {
key: 'safeSet',
value: function safeSet(data, accessor, value) {
var operation = arguments.length <= 3 || arguments[3] === undefined ? 'set' : arguments[3];
if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) !== 'object') {
throw new TypeError('safeSet Error: \'data\' is not an \'object\'.');
}
if (typeof accessor !== 'string') {
throw new TypeError('safeSet Error: \'accessor\' is not a \'string\'.');
}
var access = accessor.split('.');
// Walk through the given object by the accessor indexes.
for (var cntr = 0; cntr < access.length; cntr++) {
// If the next level of object access is undefined then create a new object entry.
if (typeof data[access[cntr]] === 'undefined') {
data[access[cntr]] = {};
}
if (cntr === access.length - 1) {
switch (operation) {
case 'add':
data[access[cntr]] += value;
break;
case 'div':
data[access[cntr]] /= value;
break;
case 'mult':
data[access[cntr]] *= value;
break;
case 'set':
data[access[cntr]] = value;
break;
case 'sub':
data[access[cntr]] -= value;
break;
}
} else {
// Abort if the next level is null or not an object and containing a value.
if (data[access[cntr]] === null || _typeof(data[access[cntr]]) !== 'object') {
return false;
}
data = data[access[cntr]];
}
}
return true;
}
}]);

@@ -105,2 +192,3 @@

* @returns {*}
* @ignore
* @private

@@ -128,2 +216,35 @@ */

}
/**
* Private implementation of `getAccessorList`.
*
* @param {object} data - An object to traverse.
*
* @returns {Array}
* @ignore
* @private
*/
function _getAccessorList(data) {
var accessors = [];
var _loop = function _loop(key) {
if (data.hasOwnProperty(key)) {
if (_typeof(data[key]) === 'object') {
var childKeys = _getAccessorList(data[key]);
childKeys.forEach(function (childKey) {
accessors.push(Array.isArray(childKey) ? key + '.' + childKey.join('.') : key + '.' + childKey);
});
} else {
accessors.push(key);
}
}
};
for (var key in data) {
_loop(key);
}
return accessors;
}
module.exports = exports['default'];

@@ -26,3 +26,2 @@ 'use strict';

*/
var StringUtil = function () {

@@ -29,0 +28,0 @@ function StringUtil() {

{
"name": "typhonjs-escomplex-commons",
"version": "0.0.11",
"version": "0.0.12",
"homepage": "https://github.com/typhonjs-node-escomplex/typhonjs-escomplex-commons/",

@@ -5,0 +5,0 @@ "description": "Provides core common utilities for typhonjs-escomplex modules and plugins.",

import AbstractReport from './AbstractReport';
import MethodAverage from './averages/MethodAverage';
import MethodReport from './MethodReport';

@@ -47,2 +48,8 @@

/**
* Stores the average method metric data.
* @type {HalsteadAverage}
*/
this.methodAverage = new MethodAverage();
/**
* The name of the class.

@@ -49,0 +56,0 @@ * @type {string}

@@ -85,12 +85,2 @@ import AbstractReport from './AbstractReport';

/**
* Provides a default array and indices for summing maintainability metrics.
*
* @returns {{sums: number[], indices: {cyclomatic: number, effort: number, loc: number, params: number}}}
*/
static getMaintainabilityMetrics()
{
return { sums: [0, 0, 0, 0], indices: s_INDICES_MAINTAINABILITY };
}
/**
* Deserializes a JSON object representing a MethodReport.

@@ -109,52 +99,2 @@ *

}
/**
* Provides a convenience method to increment metric sums given an object hash of indices.
*
* @param {Array<number>} sums - Running sums for metric calculation.
* @param {object} indices - Indices into the sums array for specific metrics.
*/
sumMetrics(sums, indices)
{
/* istanbul ignore if */
if (!Array.isArray(sums)) { throw new TypeError('sumMetrics error: `sums` is not an `array`.'); }
/* istanbul ignore if */
if (typeof indices !== 'object') { throw new TypeError('sumMetrics error: `indices` is not an `object`.'); }
for (const key in indices)
{
switch (key)
{
case 'cyclomatic':
sums[indices[key]] += this.cyclomatic;
break;
case 'effort':
sums[indices[key]] += this.halstead.effort;
break;
case 'loc':
sums[indices[key]] += this.sloc.logical;
break;
case 'params':
sums[indices[key]] += this.params;
break;
}
}
}
}
/**
* Defines the default maintainability metrics supported by `sumMetrics`.
* @type {{cyclomatic: number, effort: number, loc: number, params: number}}
* @ignore
*/
const s_INDICES_MAINTAINABILITY =
{
cyclomatic: 0,
effort: 1,
loc: 2,
params: 3
};
import AbstractReport from './AbstractReport';
import ClassReport from './ClassReport';
import MethodAverage from './averages/MethodAverage';
import MethodReport from './MethodReport';

@@ -50,8 +51,2 @@

/**
* Measures the average method cyclomatic complexity of the module / file.
* @type {number}
*/
this.cyclomatic = 0;
/**
* Stores all parsed dependencies.

@@ -63,8 +58,2 @@ * @type {Array}

/**
* Measures the average method maintenance effort of the module / file.
* @type {number}
*/
this.effort = 0;
/**
* Stores the file path of the module / file. The file path is only defined as supplied when processing projects.

@@ -88,8 +77,2 @@ * @type {string}

/**
* Measures the average method logical SLOC (source lines of code) for the module / file.
* @type {number}
*/
this.loc = 0;
/**
* Measures the average method maintainability index for the module / file.

@@ -107,6 +90,6 @@ * @type {number}

/**
* Measures the average number of method parameters for the module / file.
* @type {number}
* Stores the average method metric data.
* @type {MethodAverage}
*/
this.params = 0;
this.methodAverage = new MethodAverage();

@@ -279,12 +262,2 @@ /**

/**
* Provides a default array and indices for summing maintainability metrics via `sumMetrics`.
*
* @returns {{sums: number[], indices: {cyclomatic: number, effort: number, loc: number, maintainability: number, params: number}}}
*/
static getMaintainabilityMetrics()
{
return { sums: [0, 0, 0, 0, 0], indices: s_INDICES_MAINTAINABILITY };
}
/**
* Returns the setting indexed by the given key.

@@ -454,19 +427,2 @@ *

/**
* Provides a convenience method to increment metric sums given an object hash of indices.
*
* @param {Array<number>} sums - Running sums for metric calculation.
* @param {object} indices - Indices into the sums array for specific metrics.
*/
sumMetrics(sums, indices = {})
{
/* istanbul ignore if */
if (!Array.isArray(sums)) { throw new TypeError('sumMetrics error: `sums` is not an `array`.'); }
/* istanbul ignore if */
if (typeof indices !== 'object') { throw new TypeError('sumMetrics error: `indices` is not an `object`.'); }
for (const key in indices) { sums[indices[key]] += typeof this[key] === 'number' ? this[key] : 0; }
}
/**
* Formats this ModuleReport given the type.

@@ -485,15 +441,1 @@ *

}
/**
* Defines the default maintainability metrics supported by `sumMetrics`.
* @type {{cyclomatic: number, effort: number, loc: number, maintainability: number, params: number}}
* @ignore
*/
const s_INDICES_MAINTAINABILITY =
{
cyclomatic: 0,
effort: 1,
loc: 2,
maintainability: 3,
params: 4
};

@@ -104,9 +104,6 @@ import TraitHalstead from './TraitHalstead';

// Map all TraitHalstead data and flatten any array of identifiers returned from `valueOf` and finally convert
// all flattened identifiers to strings as necessary.
return ([].concat(...filtered.map((traitHalstead) =>
// all flattened identifier entries to strings as necessary.
return ([].concat(...filtered.map((traitHalstead) => traitHalstead.valueOf(...params)))).map((entry) =>
{
return traitHalstead.valueOf(...params);
}))).map((entry) =>
{
// Convert any undefined entry to a text string. This should only be possible when a TraitHalstead defined
// Convert any `undefined` entry to a text string. This should only occur when a TraitHalstead defined
// as a function returns an array containing `undefined`; in this case there is an issue with a syntax trait

@@ -122,2 +119,3 @@ // definition not properly verifying data.

// Convert any entries to strings as necessary.
return typeof entry !== 'string' ? JSON.stringify(entry) : entry;

@@ -124,0 +122,0 @@ });

import TransformFormat from '../../transform/TransformFormat';
import ModuleAverage from '../../module/report/averages/ModuleAverage';
import ModuleReport from '../../module/report/ModuleReport';

@@ -56,14 +57,2 @@ import MathUtil from '../../utils/MathUtil';

/**
* Measures the average method cyclomatic complexity for the project.
* @type {number}
*/
this.cyclomatic = 0;
/**
* Measures the average method maintenance effort for the project.
* @type {number}
*/
this.effort = 0;
/**
* Measures the percentage of all possible internal dependencies that are actually realized in the project.

@@ -76,20 +65,8 @@ * Lower is better.

/**
* Measures the average method logical SLOC (source lines of code) for the project.
* @type {number}
* Stores the average module metric data.
* @type {ModuleAverage}
*/
this.loc = 0;
this.moduleAverage = new ModuleAverage();
/**
* Measures the average method maintainability index for the project.
* @type {number}
*/
this.maintainability = 0;
/**
* Measures the average number of method parameters for the project.
* @type {number}
*/
this.params = 0;
/**
* Stores all ModuleReport data for the project sorted by the module / files `srcPath`.

@@ -115,15 +92,21 @@ * @type {Array<ModuleReport>}

*
* @param {boolean} serializeReports - (Optional) Allows overriding of ModuleReport serialization;
* default: undefined.
* @param {object} options - (Optional) Allows overriding of ModuleReport serialization.
* @property {boolean} serializeAverages - If serializeReports is false and serializeAverages is true then module
* averages will also be added to a reduced project result; default: false.
* @property {boolean} serializeReports - Allows overriding of ModuleReport serialization; default: true.
*
* @returns {ProjectResult}
*/
finalize(serializeReports = void 0)
finalize(options = {})
{
let serialize = this.getSetting('serializeReports');
if (typeof options !== 'object') { throw new TypeError(`finalize error: 'options' is not an 'object'.`); }
let serializeReports = this.getSetting('serializeReports', true);
let serializeAverages = this.getSetting('serializeAverages', false);
// Allow an override opportunity.
if (typeof serializeReports === 'boolean') { serialize = serializeReports; }
if (typeof options.serializeAverages === 'boolean') { serializeAverages = options.serializeAverages; }
if (typeof options.serializeReports === 'boolean') { serializeReports = options.serializeReports; }
if (serialize)
if (serializeReports)
{

@@ -136,3 +119,12 @@ this.reports.forEach((report) => { report.finalize(); });

{
return { filePath: report.filePath, srcPath: report.srcPath, srcPathAlias: report.srcPathAlias };
const modReport = { filePath: report.filePath, srcPath: report.srcPath, srcPathAlias: report.srcPathAlias };
// Potentially add module averages
if (serializeAverages)
{
modReport.maintainability = report.maintainability;
modReport.methodAverage = report.methodAverage;
}
return modReport;
});

@@ -139,0 +131,0 @@ }

@@ -64,4 +64,4 @@ /**

{
return 'json';
return 'full';
}
}
import ObjectUtil from '../../../utils/ObjectUtil';
/**
* Defines default thresholds for severity levels.
* error levels: info, warning, error
*
* entry: error, line, severity, message, source
*
* @type {{methodReport: object}}
* @ignore
*/
const s_DEFAULT_THRESHOLDS =
{
classReport:
{
maintainability: { _test: '<', info: 115, warning: 100, error: 90 }
},
methodReport:
{
'cyclomatic': { info: 3, warning: 7, error: 12 },
'halstead.difficulty': { info: 8, warning: 13, error: 20 }
},
moduleReport:
{
maintainability: { _test: '<', info: 115, warning: 100, error: 90 }
}
};
/**
* Provides a format transform for ESComplex ModuleReport / ProjectResult instances converting them to JSON that

@@ -140,5 +114,3 @@ * corresponds to the XML checkstyle format.

*
* @param {object} options - (Optional) One or more optional parameters passed to the formatter.
* @property {{info: number, warning: number, error: number}} cyclomatic - A hash of name / number thresholds.
* @property {{info: number, warning: number, error: number}} halstead - A hash of name / number thresholds.
* @param {object} options - (Optional) One or more optional entries defining threshold parameters.
*

@@ -269,2 +241,33 @@ * @returns {object}

}
}
}
// Module private ---------------------------------------------------------------------------------------------------
/**
* Defines default thresholds for severity levels matching the XML checkstyle format.
* error levels: info, warning, error
*
* Entries may include `classReport`, `methodReport`, `moduleReport` that each define an object hash of threshold
* object hashes. The key of each threshold hash is the entry key to compare against the `info, warning, error` values.
* By default the order flows left to right using greater than comparisons. An optional entry is `_test` which is a
* string defining the comparison operations with the following supported options, `<`, `<=`, `>`, and `>=`.
*
* @type {{classReport: {maintainability: {_test: string, info: number, warning: number, error: number}}, methodReport: {cyclomatic: {info: number, warning: number, error: number}, [halstead.difficulty]: {info: number, warning: number, error: number}}, moduleReport: {maintainability: {_test: string, info: number, warning: number, error: number}}}}
* @ignore
*/
const s_DEFAULT_THRESHOLDS =
{
classReport:
{
maintainability: { _test: '<', info: 115, warning: 100, error: 90 }
},
methodReport:
{
'cyclomatic': { info: 3, warning: 7, error: 12 },
'halstead.difficulty': { info: 8, warning: 13, error: 20 }
},
moduleReport:
{
maintainability: { _test: '<', info: 115, warning: 100, error: 90 }
}
};
import ObjectUtil from '../../../utils/ObjectUtil';
/**
* Defines the default keys to include in a minimal JSON representation of module / project results.
* @type {{classReport: string[], methodReport: string[], moduleReport: string[]}}
* @ignore
*/
const s_DEFAULT_KEYS =
{
classReport: ['maintainability'],
methodReport: ['cyclomatic', 'halstead.difficulty'],
moduleReport: ['maintainability']
};
/**
* Provides a format transform for ESComplex ModuleReport / ProjectResult instances converting them to JSON with

@@ -232,2 +220,16 @@ * minimal metrics.

}
}
}
// Module private ---------------------------------------------------------------------------------------------------
/**
* Defines the default keys to include in a minimal JSON representation of module / project results.
* @type {{classReport: string[], methodReport: string[], moduleReport: string[]}}
* @ignore
*/
const s_DEFAULT_KEYS =
{
classReport: ['maintainability'],
methodReport: ['cyclomatic', 'halstead.difficulty'],
moduleReport: ['maintainability']
};

@@ -35,12 +35,2 @@ import FormatText from '../text/FormatText';

}
/**
* Gets the format type.
*
* @returns {string}
*/
get type()
{
return 'markdown';
}
}

@@ -50,3 +40,4 @@

* Defines the default headers as text which are inserted via spread into `StringUtil.safeStringsObject`.
* @type {{classMethod: *[], classReport: *[], moduleMethod: *[], moduleReport: *[]}}
* @type {{classMethod: *[], classReport: *[], entryPrepend: string, moduleMethod: *[], moduleReport: *[], projectResult: string[]}}
* @ignore
*/

@@ -53,0 +44,0 @@ const s_DEFAULT_HEADERS =

import FormatTextAdjacency from '../text/FormatTextAdjacency';
/**
* Provides a format transform for ModuleReport / ProjectResult instances converting a matrix list into plain text.
* Provides a format transform for ModuleReport / ProjectResult instances converting a matrix list into markdown.
*/

@@ -38,3 +38,3 @@ export default class FormatMarkdownAdjacency extends FormatTextAdjacency

* Defines the default headers added to any output strings..
* @type {{entryPrepend: string, textHeader: string}}
* @type {{entryPrepend: string, entryWrapper: string, textHeader: string}}
* @ignore

@@ -41,0 +41,0 @@ */

@@ -41,3 +41,4 @@ import FormatTextMinimal from '../text/FormatTextMinimal';

* Defines the default headers as markdown which are inserted via spread into `StringUtil.safeStringsObject`.
* @type {{classMethod: *[], classReport: *[], moduleMethod: *[], moduleReport: *[]}}
* @type {{classMethod: *[], classReport: *[], entryPrepend: string, moduleMethod: *[], moduleReport: *[], projectResult: string[]}}
* @ignore
*/

@@ -44,0 +45,0 @@ const s_DEFAULT_HEADERS =

@@ -1,2 +0,2 @@

import AbstractFormatText from '../text/AbstractFormatText';
import FormatTextModules from '../text/FormatTextModules';

@@ -6,3 +6,3 @@ /**

*/
export default class FormatMarkdownModules extends AbstractFormatText
export default class FormatMarkdownModules extends FormatTextModules
{

@@ -33,12 +33,2 @@ constructor(headers = {}, keys = {})

}
/**
* Gets the format type.
*
* @returns {string}
*/
get type()
{
return 'modules';
}
}

@@ -50,3 +40,3 @@

* Defines markdown headers as text which are inserted via spread into `StringUtil.safeStringsObject`.
* @type {{classMethod: *[], classReport: *[], moduleMethod: *[], moduleReport: *[]}}
* @type {{moduleReport: string[]}}
* @ignore

@@ -53,0 +43,0 @@ */

import FormatTextVisibility from '../text/FormatTextVisibility';
/**
* Provides a format transform for ModuleReport / ProjectResult instances converting a matrix list into plain text.
* Provides a format transform for ModuleReport / ProjectResult instances converting a matrix list into markdown.
*/

@@ -38,3 +38,3 @@ export default class FormatMarkdownVisibility extends FormatTextVisibility

* Defines the default headers added to any output strings..
* @type {{entryPrepend: string, textHeader: string}}
* @type {{entryPrepend: string, entryWrapper: string, textHeader: string}}
* @ignore

@@ -41,0 +41,0 @@ */

@@ -8,2 +8,9 @@ import StringUtil from '../../../utils/StringUtil';

{
/**
* Initializes instance storing default headers / keys.
*
* @param {object} headers - An object hash of header entries formatted for `StringUtil.safeStringsObject`.
*
* @param {object} keys - An object hash of key entries formatted for `StringUtil.safeStringsObject`.
*/
constructor(headers = {}, keys = {})

@@ -105,2 +112,3 @@ {

* @returns {string}
* @private
*/

@@ -132,2 +140,3 @@ _formatClass(classReport, options, prepend = '')

* @returns {string}
* @private
*/

@@ -154,2 +163,3 @@ _formatClasses(classReports, options, prepend = '')

* @returns {string}
* @private
*/

@@ -196,2 +206,3 @@ _formatEntries(report, entries, prepend = '')

* @returns {string}
* @private
*/

@@ -224,2 +235,3 @@ _formatMethod(methodReport, options, prepend = '', isModule = true)

* @returns {string}
* @private
*/

@@ -244,7 +256,8 @@ _formatMethods(methodReports, options, prepend = '', isModule = true)

* @param {object} options - (Optional) One or more optional parameters passed to the formatter.
* @property {string} classReport - An entry key found in the ClassReport to output.
* @property {string} methodReport - An entry key found in the MethodReport to output.
* @property {string} moduleReport - An entry key found in the ModuleReport to output.
* @property {string} classReport - Entry keys found in the ClassReport to output.
* @property {string} methodReport - Entry keys found in the MethodReport to output.
* @property {string} moduleReport - Entry keys found in the ModuleReport to output.
*
* @returns {string}
* @private
*/

@@ -273,2 +286,13 @@ _formatModule(moduleReport, reportsAvailable, options)

/**
* Formats a project result.
*
* @param {ProjectResult} projectResult - A project result.
*
* @param {object} options - (Optional) One or more optional parameters passed to the formatter.
* @property {string} projectResult - Entry keys found in the ProjectReport to output.
*
* @returns {string}
* @private
*/
_formatProject(projectResult, options)

@@ -275,0 +299,0 @@ {

@@ -8,2 +8,15 @@ import ObjectUtil from '../../../utils/ObjectUtil';

{
/**
* Initializes instance storing default headers / keys.
*
* @param {object} headers - An object hash containing the following entries.
* @property {string} entryPrepend - A string to prepend all entries.
* @property {string} entryWrapper - A string to wrap output entries between.
* @property {string} textHeader - A string to prepend output providing a leading header.
*
* @param {object} keys - An object hash containing the following entries.
* @property {boolean} matrixFilePath - If true the module `filePath` is serialized.
* @property {string} matrixList - An entry key to lookup a given matrix list in a ProjectResult.
* @property {boolean} zeroIndex - If true module report indexes are zero indexed.
*/
constructor(headers = {}, keys = {})

@@ -31,4 +44,6 @@ {

*
* @param {object} options - (Optional) One or more optional parameters passed to the formatter.
* @property {string} matrixKey - An entry key found in the ProjectResult to output.
* @param {object} options - (Optional) An object hash containing the following entries.
* @property {boolean} matrixFilePath - If true the module `filePath` is serialized.
* @property {string} matrixList - An entry key to lookup a given matrix list in a ProjectResult.
* @property {boolean} zeroIndex - If true module report indexes are zero indexed.
*

@@ -87,4 +102,4 @@ * @returns {string}

* @param {object} options - (Optional) An object hash of options.
* @propert {boolean} zeroIndex - If true module report indexes are zero indexed.
* @propert {boolean} matrixFilePath - If true the module `filePath` is serialized.
* @property {boolean} zeroIndex - If true module report indexes are zero indexed.
* @property {boolean} matrixFilePath - If true the module `filePath` is serialized.
*

@@ -107,3 +122,3 @@ * @returns {string}

output += `${entryPrepend}${entry.row + plus1}:\t${entryWrapper}${ObjectUtil.safeAccess(
result.reports[entry.row], path)}${entryWrapper}\n`;
result.reports[entry.row], path, 'unknown')}${entryWrapper}\n`;

@@ -113,3 +128,3 @@ entry.cols.forEach((colIndex) =>

output += `\t${entryPrepend}${colIndex + plus1}:\t${entryWrapper}${ObjectUtil.safeAccess(
result.reports[colIndex], path)}${entryWrapper}\n`;
result.reports[colIndex], path, 'unknown')}${entryWrapper}\n`;
});

@@ -116,0 +131,0 @@

@@ -83,3 +83,3 @@ import AbstractFormatText from './AbstractFormatText';

{
return 'text';
return 'full';
}

@@ -90,18 +90,31 @@ }

const s_SHARED_DATA =
const s_SHARED_METHOD_DATA =
[
['Line start: ', 'lineStart'],
['Line end: ', 'lineEnd'],
['Physical LOC: ', 'sloc.physical'],
['Logical LOC: ', 'sloc.logical'],
['Cyclomatic complexity: ', 'cyclomatic'],
['Cyclomatic complexity density: ', 'cyclomaticDensity', 1, '%'],
['Halstead difficulty: ', 'halstead.difficulty'],
['Halstead volume: ', 'halstead.volume'],
['Halstead effort: ', 'halstead.effort']
['Line start: ', 'lineStart'],
['Line end: ', 'lineEnd'],
['Physical LOC: ', 'sloc.physical'],
['Logical LOC: ', 'sloc.logical'],
['Cyclomatic complexity: ', 'cyclomatic'],
['Cyclomatic complexity density: ', 'cyclomaticDensity', 1, '%'],
['Halstead difficulty: ', 'halstead.difficulty'],
['Halstead volume: ', 'halstead.volume'],
['Halstead effort: ', 'halstead.effort'],
['Parameter count: ', 'params']
];
const s_SHARED_METHOD_AVERAGE_DATA =
[
['Average per-function physical LOC: ', 'methodAverage.sloc.physical'],
['Average per-function logical LOC: ', 'methodAverage.sloc.logical'],
['Average per-function cyclomatic complexity: ', 'methodAverage.cyclomatic'],
['Average per-function cyclomatic density: ', 'methodAverage.cyclomaticDensity', 1, '%'],
['Average per-function halstead difficulty: ', 'methodAverage.halstead.difficulty'],
['Average per-function halstead volume: ', 'methodAverage.halstead.volume'],
['Average per-function halstead effort: ', 'methodAverage.halstead.effort']
];
/**
* Defines the default headers as text which are inserted via spread into `StringUtil.safeStringsObject`.
* @type {{classMethod: *[], classReport: *[], moduleMethod: *[], moduleReport: *[]}}
* @type {{classMethod: Array, classReport: Array, methodReport: *[], moduleReport: *[], projectResult: *[]}}
* @ignore
*/

@@ -112,3 +125,3 @@ const s_DEFAULT_KEYS =

[
...s_SHARED_DATA
...s_SHARED_METHOD_DATA
],

@@ -118,3 +131,5 @@

[
...s_SHARED_DATA
['Line start: ', 'lineStart'],
['Line end: ', 'lineEnd'],
...s_SHARED_METHOD_AVERAGE_DATA
],

@@ -124,4 +139,3 @@

[
...s_SHARED_DATA,
['Parameter count: ', 'params']
...s_SHARED_METHOD_DATA
],

@@ -131,5 +145,6 @@

[
...s_SHARED_DATA,
['Maintainability index: ', 'maintainability'],
['Dependency count: ', 'dependencies.length']
['Total lines: ', 'lineEnd'],
['Maintainability index: ', 'maintainability'],
['Dependency count: ', 'dependencies.length'],
...s_SHARED_METHOD_AVERAGE_DATA
],

@@ -139,10 +154,12 @@

[
['Mean per-function logical LOC: ', 'loc'],
['Mean per-function parameter count: ', 'params'],
['Mean per-function cyclomatic complexity: ', 'cyclomatic'],
['Mean per-function Halstead effort: ', 'effort'],
['Mean per-module maintainability index: ', 'maintainability'],
['First-order density: ', 'firstOrderDensity', 1, '%'],
['Change cost: ', 'changeCost', 1, '%'],
['Core size: ', 'coreSize', 1, '%']
['First-order density: ', 'firstOrderDensity', 1, '%'],
['Change cost: ', 'changeCost', 1, '%'],
['Core size: ', 'coreSize', 1, '%'],
['Average per-module maintainability index: ', 'moduleAverage.maintainability'],
['Average per-function physical LOC: ', 'moduleAverage.methodAverage.sloc.physical'],
['Average per-function logical LOC: ', 'moduleAverage.methodAverage.sloc.logical'],
['Average per-function parameter count: ', 'moduleAverage.methodAverage.params'],
['Average per-function cyclomatic complexity: ', 'moduleAverage.methodAverage.cyclomatic'],
['Average per-function halstead difficulty: ', 'moduleAverage.methodAverage.halstead.difficulty'],
['Average per-function halstead effort: ', 'moduleAverage.methodAverage.halstead.effort']
]

@@ -154,2 +171,3 @@ };

* @type {{classMethod: *[], classReport: *[], entryPrepend: string, moduleMethod: *[], moduleReport: string[], projectResult: string[]}}
* @ignore
*/

@@ -156,0 +174,0 @@ const s_DEFAULT_HEADERS =

@@ -59,3 +59,3 @@ import AbstractTextMatrix from './AbstractTextMatrix';

* Defines the default headers added to any output strings..
* @type {{entryPrepend: string, textHeader: string}}
* @type {{entryPrepend: string, entryWrapper: string, textHeader: string}}
* @ignore

@@ -62,0 +62,0 @@ */

@@ -50,3 +50,3 @@ import AbstractFormatTest from './AbstractFormatText';

* Defines the default keys to include in a minimal text representation of module / project results.
* @type {{classReport: string[], methodReport: string[], moduleReport: string[]}}
* @type {{classReport: string[], methodReport: string[], moduleReport: string[], projectResult: string[]}}
* @ignore

@@ -59,3 +59,3 @@ */

moduleReport: ['maintainability'],
projectResult: ['maintainability']
projectResult: ['moduleAverage.maintainability']
};

@@ -65,3 +65,4 @@

* Defines the default headers as text which are inserted via spread into `StringUtil.safeStringsObject`.
* @type {{classMethod: *[], classReport: *[], moduleMethod: *[], moduleReport: *[]}}
* @type {{classMethod: *[], classReport: *[], entryPrepend: string, moduleMethod: *[], moduleReport: *[], projectResult: string[]}}
* @ignore
*/

@@ -68,0 +69,0 @@ const s_DEFAULT_HEADERS =

@@ -48,4 +48,5 @@ import AbstractFormatTest from './AbstractFormatText';

/**
*
* Defines markdown headers as text which are inserted via spread into `StringUtil.safeStringsObject`.
* @type {{moduleReport: *[]}}
* @ignore
*/

@@ -52,0 +53,0 @@ const s_DEFAULT_HEADERS =

@@ -59,3 +59,3 @@ import AbstractTextMatrix from './AbstractTextMatrix';

* Defines the default headers added to any output strings..
* @type {{entryPrepend: string, textHeader: string}}
* @type {{entryPrepend: string, entryWrapper: string, textHeader: string}}
* @ignore

@@ -62,0 +62,0 @@ */

@@ -27,2 +27,16 @@ /**

/**
* Returns a list of accessor keys by traversing the given object.
*
* @param {object} data - An object to traverse for accessor keys.
*
* @returns {Array}
*/
static getAccessorList(data)
{
if (typeof data !== 'object') { throw new TypeError(`getAccessorList error: 'data' is not an 'object'.`); }
return _getAccessorList(data);
}
/**
* Provides a way to safely access an objects data / entries given an accessor string which describes the

@@ -32,3 +46,3 @@ * entries to walk. To access deeper entries into the object format the accessor string with `.` between entries

*
* @param {object} object - An object to access entry data.
* @param {object} data - An object to access entry data.
* @param {string} accessor - A string describing the entries to access.

@@ -39,5 +53,5 @@ * @param {*} defaultValue - (Optional) A default value to return if an entry for accessor is not found.

*/
static safeAccess(object, accessor, defaultValue = undefined)
static safeAccess(data, accessor, defaultValue = undefined)
{
if (typeof object !== 'object') { return defaultValue; }
if (typeof data !== 'object') { return defaultValue; }
if (typeof accessor !== 'string') { return defaultValue; }

@@ -51,9 +65,72 @@

// If the next level of object access is undefined or null then return the empty string.
if (typeof object[access[cntr]] === 'undefined' || object[access[cntr]] === null) { return defaultValue; }
if (typeof data[access[cntr]] === 'undefined' || data[access[cntr]] === null) { return defaultValue; }
object = object[access[cntr]];
data = data[access[cntr]];
}
return object;
return data;
}
/**
* Provides a way to safely set an objects data / entries given an accessor string which describes the
* entries to walk. To access deeper entries into the object format the accessor string with `.` between entries
* to walk.
*
* @param {object} data - An object to access entry data.
* @param {string} accessor - A string describing the entries to access.
* @param {*} value - A new value to set if an entry for accessor is found.
* @param {string} operation - (Optional) Operation to perform including: 'add', 'div', 'mult', 'set', 'sub';
* default (`set`).
*
* @returns {boolean} True if successful.
*/
static safeSet(data, accessor, value, operation = 'set')
{
if (typeof data !== 'object') { throw new TypeError(`safeSet Error: 'data' is not an 'object'.`); }
if (typeof accessor !== 'string') { throw new TypeError(`safeSet Error: 'accessor' is not a 'string'.`); }
const access = accessor.split('.');
// Walk through the given object by the accessor indexes.
for (let cntr = 0; cntr < access.length; cntr++)
{
// If the next level of object access is undefined then create a new object entry.
if (typeof data[access[cntr]] === 'undefined') { data[access[cntr]] = {}; }
if (cntr === access.length - 1)
{
switch (operation)
{
case 'add':
data[access[cntr]] += value;
break;
case 'div':
data[access[cntr]] /= value;
break;
case 'mult':
data[access[cntr]] *= value;
break;
case 'set':
data[access[cntr]] = value;
break;
case 'sub':
data[access[cntr]] -= value;
break;
}
}
else
{
// Abort if the next level is null or not an object and containing a value.
if (data[access[cntr]] === null || typeof data[access[cntr]] !== 'object') { return false; }
data = data[access[cntr]];
}
}
return true;
}
}

@@ -70,2 +147,3 @@

* @returns {*}
* @ignore
* @private

@@ -89,2 +167,38 @@ */

return data;
}
}
/**
* Private implementation of `getAccessorList`.
*
* @param {object} data - An object to traverse.
*
* @returns {Array}
* @ignore
* @private
*/
function _getAccessorList(data)
{
const accessors = [];
for (const key in data)
{
if (data.hasOwnProperty(key))
{
if (typeof data[key] === 'object')
{
const childKeys = _getAccessorList(data[key]);
childKeys.forEach((childKey) =>
{
accessors.push(Array.isArray(childKey) ? `${key}.${childKey.join('.')}` : `${key}.${childKey}`);
});
}
else
{
accessors.push(key);
}
}
}
return accessors;
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc