Skip to content

Maintainability index calculation (Cyclomatic complexity) #14

@abdullahkady

Description

@abdullahkady

Hi there,

First things first, nice work!
I have found a small problem with the calculation of the Maintainability Index formula used in: https://github.com/typhonjs-node-escomplex/escomplex-plugin-metrics-module
The following line:
(0.23 * averageCyclomatic === 0 ? 0 : Math.log(averageCyclomatic))
The ternary expression used does not evaluate as intended. It evaluates to 0.23 * averageCyclomatic rather than 0.23 * Math.log(averageCyclomatic) whenever the averageCyclomatic is not a zero, as stated in the documentation:
https://github.com/typhonjs-node-escomplex/escomplex-plugin-metrics-module/blob/7a4ddb6a0def5c90b8aa2f06c3e0867ba10eacd6/src/ModuleMetricPostAverage.js#L45-L49

A quick fix is to update the expression, by wrapping the ternary expression with brackets, leading to proper evaluation of the expression.

I have fixed it in a PR here if suitable: typhonjs-node-escomplex/escomplex-plugin-metrics-module#1

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions