Home Manual Reference Source Test Repository
public class | source

PluginMetricsModule

Provides a typhonjs-escomplex-module / ESComplexModule plugin which gathers and calculates all default metrics.

See:

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

Loads any default settings that are not already provided by any user options.

public

During AST traversal when a node is entered it is processed immediately if the node type corresponds to a loaded trait syntax.

public

During AST traversal when a node is exited it is processed immediately if the node type corresponds to a loaded trait syntax.

public

Performs final calculations based on collected report data.

public

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:

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.

private

_calculateMetrics(report: ModuleReport)

Coordinates calculating all metrics.

Public Members

public settings: object source

Stores the settings for all ESComplexModule plugins.

public syntaxes: object source

Stores the trait syntaxes loaded by other ESComplexModule plugins.

Public Methods

public onConfigure(ev: object) source

Loads any default settings that are not already provided by any user options.

Params:

NameTypeAttributeDescription
ev object

escomplex plugin event data.

The following options are:

(boolean)   newmi - Boolean indicating whether the maintainability index should be rebased on a scale from
                    0 to 100; defaults to false.

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
ev object

escomplex plugin event data.

public onModuleEnd(ev: object) source

Performs final calculations based on collected report data.

Params:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
halstead HalsteadData

A HalsteadData instance to perform calculations on.

See:

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
report ModuleReport

The ModuleReport being processed.