Socket
Socket
Sign inDemoInstall

escomplex-plugin-metrics-project

Package Overview
Dependencies
1
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.8 to 0.0.9

68

dist/PluginMetricsProject.js

@@ -54,3 +54,3 @@ 'use strict';

/**
* Performs final calculations based on collected results data.
* Performs final calculations based on collected project report data.
*

@@ -64,12 +64,12 @@ * @param {object} ev - escomplex plugin event data.

var pathModule = ev.data.pathModule;
var projectResult = ev.data.results;
var projectReport = ev.data.projectReport;
var adjacencyMatrix = this._calculateAdjacencyMatrix(pathModule, projectResult);
var adjacencyMatrix = this._calculateAdjacencyMatrix(pathModule, projectReport);
if (!this.settings.noCoreSize) {
var visibilityMatrix = this._calculateVisibilityMatrix(projectResult, adjacencyMatrix);
this._calculateCoreSize(projectResult, visibilityMatrix);
var visibilityMatrix = this._calculateVisibilityMatrix(projectReport, adjacencyMatrix);
this._calculateCoreSize(projectReport, visibilityMatrix);
}
this._calculateAverages(projectResult);
this._calculateAverages(projectReport);
}

@@ -97,8 +97,8 @@

* Calculates an adjacency matrix for all modules based on ES Module and CommonJS dependencies also storing a
* compacted while returning the matrix for further calculation. Each row index corresponds to the same report index.
* Each row entry corresponds to a report index. These relationships dictate the dependencies between all
* report ModuleReports given the source paths.
* compacted while returning the matrix for further calculation. Each row index corresponds to the same module index.
* Each row entry corresponds to a module index. These relationships dictate the dependencies between all
* module ModuleReports given the source paths.
*
* @param {object} pathModule - A module that conforms to the Node path API.
* @param {object} projectResult - The ProjectResult being processed.
* @param {object} projectReport - The ProjectResult being processed.
*

@@ -111,5 +111,5 @@ * @returns {Array<Array<number>>}

key: '_calculateAdjacencyMatrix',
value: function _calculateAdjacencyMatrix(pathModule, projectResult) {
var reports = projectResult.reports;
var length = reports.length;
value: function _calculateAdjacencyMatrix(pathModule, projectReport) {
var modules = projectReport.modules;
var length = modules.length;

@@ -122,3 +122,3 @@ var adjacencyMatrix = _MathUtil2.default.create2DArray(length, 0);

for (var y = 0; y < length; y++) {
adjacencyMatrix[x][y] = x !== y && this._doesDependencyExist(pathModule, reports[x], reports[y]) ? 1 : 0;
adjacencyMatrix[x][y] = x !== y && this._doesDependencyExist(pathModule, modules[x], modules[y]) ? 1 : 0;

@@ -131,5 +131,5 @@ if (adjacencyMatrix[x][y] === 1) {

projectResult.adjacencyList = _MathUtil2.default.compactMatrix(adjacencyMatrix);
projectReport.adjacencyList = _MathUtil2.default.compactMatrix(adjacencyMatrix);
projectResult.firstOrderDensity = _MathUtil2.default.getPercent(density, length * length);
projectReport.firstOrderDensity = _MathUtil2.default.getPercent(density, length * length);

@@ -142,3 +142,3 @@ return adjacencyMatrix;

*
* @param {object} projectResult - The ProjectResult being processed.
* @param {object} projectReport - The ProjectResult being processed.
*

@@ -150,12 +150,12 @@ * @private

key: '_calculateAverages',
value: function _calculateAverages(projectResult) {
var divisor = projectResult.reports.length === 0 ? 1 : projectResult.reports.length;
value: function _calculateAverages(projectReport) {
var divisor = projectReport.modules.length === 0 ? 1 : projectReport.modules.length;
var moduleAverage = projectResult.moduleAverage;
var moduleAverage = projectReport.moduleAverage;
var moduleAverageKeys = _ObjectUtil2.default.getAccessorList(moduleAverage);
// Defer to ModuleReport to sum all relevant module metrics applicable to ProjectResult.
projectResult.reports.forEach(function (report) {
projectReport.modules.forEach(function (module) {
moduleAverageKeys.forEach(function (averageKey) {
var targetValue = _ObjectUtil2.default.safeAccess(report, averageKey, 0);
var targetValue = _ObjectUtil2.default.safeAccess(module, averageKey, 0);
_ObjectUtil2.default.safeSet(moduleAverage, averageKey, targetValue, 'add');

@@ -174,3 +174,3 @@ });

*
* @param {object} projectResult - The ProjectResult being processed.
* @param {object} projectReport - The ProjectResult being processed.
* @param {Array<Array<number>>} visibilityMatrix - The calculated visibilityMatrix.

@@ -183,5 +183,5 @@ *

key: '_calculateCoreSize',
value: function _calculateCoreSize(projectResult, visibilityMatrix) {
if (projectResult.firstOrderDensity === 0) {
projectResult.coreSize = 0;
value: function _calculateCoreSize(projectReport, visibilityMatrix) {
if (projectReport.firstOrderDensity === 0) {
projectReport.coreSize = 0;
return;

@@ -220,9 +220,9 @@ }

projectResult.coreSize = _MathUtil2.default.getPercent(coreSize, length);
projectReport.coreSize = _MathUtil2.default.getPercent(coreSize, length);
}
/**
* Stores a compacted form of the visibility matrix. Each row index corresponds to the same report index.
* Each row entry corresponds to a report index. These relationships dictate the reverse visibility between all
* report ModuleReports which may indirectly impact the given module / file. The full matrix is returned for further
* Stores a compacted form of the visibility matrix. Each row index corresponds to the same module index.
* Each row entry corresponds to a module index. These relationships dictate the reverse visibility between all
* module ModuleReports which may indirectly impact the given module / file. The full matrix is returned for further
* calculation.

@@ -233,3 +233,3 @@ *

*
* @param {object} projectResult - The ProjectResult being processed.
* @param {object} projectReport - The ProjectResult being processed.
* @param {Array<Array<number>>} adjacencyMatrix - The calculated adjacencyMatrix.

@@ -243,3 +243,3 @@ *

key: '_calculateVisibilityMatrix',
value: function _calculateVisibilityMatrix(projectResult, adjacencyMatrix) {
value: function _calculateVisibilityMatrix(projectReport, adjacencyMatrix) {
var changeCost = 0;

@@ -284,5 +284,5 @@

projectResult.visibilityList = _MathUtil2.default.compactMatrix(visibilityMatrix);
projectReport.visibilityList = _MathUtil2.default.compactMatrix(visibilityMatrix);
projectResult.changeCost = _MathUtil2.default.getPercent(changeCost, length * length);
projectReport.changeCost = _MathUtil2.default.getPercent(changeCost, length * length);

@@ -289,0 +289,0 @@ return visibilityMatrix;

{
"name": "escomplex-plugin-metrics-project",
"version": "0.0.8",
"version": "0.0.9",
"homepage": "https://github.com/typhonjs-node-escomplex/escomplex-plugin-metrics-project/",

@@ -23,3 +23,3 @@ "description": "Provides the core project metric / report generation plugin for typhonjs-escomplex project processing.",

"dependencies": {
"typhonjs-escomplex-commons": "^0.0.12"
"typhonjs-escomplex-commons": "^0.0.13"
},

@@ -26,0 +26,0 @@ "devDependencies": {

@@ -33,3 +33,3 @@ import MathUtil from 'typhonjs-escomplex-commons/src/utils/MathUtil';

/**
* Performs final calculations based on collected results data.
* Performs final calculations based on collected project report data.
*

@@ -41,13 +41,13 @@ * @param {object} ev - escomplex plugin event data.

const pathModule = ev.data.pathModule;
const projectResult = ev.data.results;
const projectReport = ev.data.projectReport;
const adjacencyMatrix = this._calculateAdjacencyMatrix(pathModule, projectResult);
const adjacencyMatrix = this._calculateAdjacencyMatrix(pathModule, projectReport);
if (!this.settings.noCoreSize)
{
const visibilityMatrix = this._calculateVisibilityMatrix(projectResult, adjacencyMatrix);
this._calculateCoreSize(projectResult, visibilityMatrix);
const visibilityMatrix = this._calculateVisibilityMatrix(projectReport, adjacencyMatrix);
this._calculateCoreSize(projectReport, visibilityMatrix);
}
this._calculateAverages(projectResult);
this._calculateAverages(projectReport);
}

@@ -73,8 +73,8 @@

* Calculates an adjacency matrix for all modules based on ES Module and CommonJS dependencies also storing a
* compacted while returning the matrix for further calculation. Each row index corresponds to the same report index.
* Each row entry corresponds to a report index. These relationships dictate the dependencies between all
* report ModuleReports given the source paths.
* compacted while returning the matrix for further calculation. Each row index corresponds to the same module index.
* Each row entry corresponds to a module index. These relationships dictate the dependencies between all
* module ModuleReports given the source paths.
*
* @param {object} pathModule - A module that conforms to the Node path API.
* @param {object} projectResult - The ProjectResult being processed.
* @param {object} projectReport - The ProjectResult being processed.
*

@@ -84,6 +84,6 @@ * @returns {Array<Array<number>>}

*/
_calculateAdjacencyMatrix(pathModule, projectResult)
_calculateAdjacencyMatrix(pathModule, projectReport)
{
const reports = projectResult.reports;
const length = reports.length;
const modules = projectReport.modules;
const length = modules.length;

@@ -98,3 +98,3 @@ const adjacencyMatrix = MathUtil.create2DArray(length, 0);

{
adjacencyMatrix[x][y] = x !== y && this._doesDependencyExist(pathModule, reports[x], reports[y]) ? 1 : 0;
adjacencyMatrix[x][y] = x !== y && this._doesDependencyExist(pathModule, modules[x], modules[y]) ? 1 : 0;

@@ -105,5 +105,5 @@ if (adjacencyMatrix[x][y] === 1) { density += 1; }

projectResult.adjacencyList = MathUtil.compactMatrix(adjacencyMatrix);
projectReport.adjacencyList = MathUtil.compactMatrix(adjacencyMatrix);
projectResult.firstOrderDensity = MathUtil.getPercent(density, length * length);
projectReport.firstOrderDensity = MathUtil.getPercent(density, length * length);

@@ -116,19 +116,19 @@ return adjacencyMatrix;

*
* @param {object} projectResult - The ProjectResult being processed.
* @param {object} projectReport - The ProjectResult being processed.
*
* @private
*/
_calculateAverages(projectResult)
_calculateAverages(projectReport)
{
const divisor = projectResult.reports.length === 0 ? 1 : projectResult.reports.length;
const divisor = projectReport.modules.length === 0 ? 1 : projectReport.modules.length;
const moduleAverage = projectResult.moduleAverage;
const moduleAverage = projectReport.moduleAverage;
const moduleAverageKeys = ObjectUtil.getAccessorList(moduleAverage);
// Defer to ModuleReport to sum all relevant module metrics applicable to ProjectResult.
projectResult.reports.forEach((report) =>
projectReport.modules.forEach((module) =>
{
moduleAverageKeys.forEach((averageKey) =>
{
const targetValue = ObjectUtil.safeAccess(report, averageKey, 0);
const targetValue = ObjectUtil.safeAccess(module, averageKey, 0);
ObjectUtil.safeSet(moduleAverage, averageKey, targetValue, 'add');

@@ -148,3 +148,3 @@ });

*
* @param {object} projectResult - The ProjectResult being processed.
* @param {object} projectReport - The ProjectResult being processed.
* @param {Array<Array<number>>} visibilityMatrix - The calculated visibilityMatrix.

@@ -154,7 +154,7 @@ *

*/
_calculateCoreSize(projectResult, visibilityMatrix)
_calculateCoreSize(projectReport, visibilityMatrix)
{
if (projectResult.firstOrderDensity === 0)
if (projectReport.firstOrderDensity === 0)
{
projectResult.coreSize = 0;
projectReport.coreSize = 0;
return;

@@ -191,9 +191,9 @@ }

projectResult.coreSize = MathUtil.getPercent(coreSize, length);
projectReport.coreSize = MathUtil.getPercent(coreSize, length);
}
/**
* Stores a compacted form of the visibility matrix. Each row index corresponds to the same report index.
* Each row entry corresponds to a report index. These relationships dictate the reverse visibility between all
* report ModuleReports which may indirectly impact the given module / file. The full matrix is returned for further
* Stores a compacted form of the visibility matrix. Each row index corresponds to the same module index.
* Each row entry corresponds to a module index. These relationships dictate the reverse visibility between all
* module ModuleReports which may indirectly impact the given module / file. The full matrix is returned for further
* calculation.

@@ -204,3 +204,3 @@ *

*
* @param {object} projectResult - The ProjectResult being processed.
* @param {object} projectReport - The ProjectResult being processed.
* @param {Array<Array<number>>} adjacencyMatrix - The calculated adjacencyMatrix.

@@ -211,3 +211,3 @@ *

*/
_calculateVisibilityMatrix(projectResult, adjacencyMatrix)
_calculateVisibilityMatrix(projectReport, adjacencyMatrix)
{

@@ -259,5 +259,5 @@ let changeCost = 0;

projectResult.visibilityList = MathUtil.compactMatrix(visibilityMatrix);
projectReport.visibilityList = MathUtil.compactMatrix(visibilityMatrix);
projectResult.changeCost = MathUtil.getPercent(changeCost, length * length);
projectReport.changeCost = MathUtil.getPercent(changeCost, length * length);

@@ -264,0 +264,0 @@ return visibilityMatrix;

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc