import PluginMetricsModule from 'escomplex-plugin-metrics-module/src/PluginMetricsModule.js'
PluginMetricsModule
Provides a typhonjs-escomplex-module / ESComplexModule plugin which gathers and calculates all default metrics.
Member Summary
Public Members | ||
public |
Stores the settings for all ESComplexModule plugins. |
|
public |
Stores the trait syntaxes loaded by other ESComplexModule plugins. |
Method Summary
Public Methods | ||
public |
onConfigure(ev: object) Loads any default settings that are not already provided by any user options. |
|
public |
onEnterNode(ev: object) During AST traversal when a node is entered it is processed immediately if the node type corresponds to a loaded trait syntax. |
|
public |
onExitNode(ev: object) During AST traversal when a node is exited it is processed immediately if the node type corresponds to a loaded trait syntax. |
|
public |
onModuleEnd(ev: object) Performs final calculations based on collected report data. |
|
public |
onModuleStart(ev: object) Stores settings and syntaxes, initializes local variables and creates the initial aggregate report. |
Private Methods | ||
private |
_calculateCyclomaticDensity(report: MethodReport) Calculates cyclomatic density - Proposed as a modification to cyclomatic complexity by Geoffrey K. |
|
private |
_calculateHalsteadMetrics(halstead: HalsteadData) Calculates Halstead metrics. |
|
private |
_calculateMaintainabilityIndex(report: ClassReport | ModuleReport, averageCyclomatic: number, averageEffort: number, averageLoc: number) Designed in 1991 by Paul Oman and Jack Hagemeister at the University of Idaho, this metric is calculated at the whole program or module level from averages of the other 3 metrics, using the following formula:
Values are on a logarithmic scale ranging from negative infinity up to 171, with greater numbers indicating a higher level of maintainability. |
|
private |
_calculateMetrics(report: ModuleReport) Coordinates calculating all metrics. |
Public Members
Public Methods
public onConfigure(ev: object) source
Loads any default settings that are not already provided by any user options.
Params:
Name | Type | Attribute | Description |
ev | object | escomplex plugin event data. The following options are:
|
public onEnterNode(ev: object) source
During AST traversal when a node is entered it is processed immediately if the node type corresponds to a
loaded trait syntax. Any new report scopes are handled in onEnterNode
.
Params:
Name | Type | Attribute | Description |
ev | object | escomplex plugin event data. |
public onExitNode(ev: object) source
During AST traversal when a node is exited it is processed immediately if the node type corresponds to a
loaded trait syntax. If a node has a new report scope it is popped in onExitNode
.
Params:
Name | Type | Attribute | Description |
ev | object | escomplex plugin event data. |
public onModuleEnd(ev: object) source
Performs final calculations based on collected report data.
Params:
Name | Type | Attribute | Description |
ev | object | escomplex plugin event data. |
public onModuleStart(ev: object) source
Stores settings and syntaxes, initializes local variables and creates the initial aggregate report.
Params:
Name | Type | Attribute | Description |
ev | object | escomplex plugin event data. |
Private Methods
private _calculateCyclomaticDensity(report: MethodReport) source
Calculates cyclomatic density - Proposed as a modification to cyclomatic complexity by Geoffrey K. Gill and Chris F. Kemerer in 1991, this metric simply re-expresses it as a percentage of the logical lines of code. Lower is better.
Params:
Name | Type | Attribute | Description |
report | MethodReport | A MethodReport to perform calculations on. |
private _calculateHalsteadMetrics(halstead: HalsteadData) source
Calculates Halstead metrics. In 1977, Maurice Halstead developed a set of metrics which are calculated based on the number of distinct operators, the number of distinct operands, the total number of operators and the total number of operands in each function. This site picks out three Halstead measures in particular: difficulty, volume and effort.
Params:
Name | Type | Attribute | Description |
halstead | HalsteadData | A HalsteadData instance to perform calculations on. |
private _calculateMaintainabilityIndex(report: ClassReport | ModuleReport, averageCyclomatic: number, averageEffort: number, averageLoc: number) source
Designed in 1991 by Paul Oman and Jack Hagemeister at the University of Idaho, this metric is calculated at the whole program or module level from averages of the other 3 metrics, using the following formula:
171 -
(3.42 ln(mean effort)) -
(0.23 ln(mean cyclomatic complexity)) -
(16.2 * ln(mean logical LOC))
Values are on a logarithmic scale ranging from negative infinity up to 171, with greater numbers indicating a higher level of maintainability. In their original paper, Oman and Hagemeister identified 65 as the threshold value below which a program should be considered difficult to maintain.
Params:
Name | Type | Attribute | Description |
report | ClassReport | ModuleReport | A ClassReport or ModuleReport to perform calculations on. |
|
averageCyclomatic | number | Average cyclomatic metric across a ClassReport / ModuleReport. |
|
averageEffort | number | Average Halstead effort across a ClassReport / ModuleReport. |
|
averageLoc | number | Average SLOC metric across a ClassReport / ModuleReport. |
private _calculateMetrics(report: ModuleReport) source
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.
Params:
Name | Type | Attribute | Description |
report | ModuleReport | The ModuleReport being processed. |