Calculates Halstead Matrices, Cyclomatic Complexity and Maintainability for Typescript
npm install ts-complex```
npm install ts-complex
const tscomplex = require('ts-complex');const path = './test.ts'; // Finding maintainability of this file
const maintainability = tscomplex.calculateMaintainability(path);
console.log(maintainability); // { averageMaintainability: 56.14, minMaintainability: 46.19 }
`
Halstead Complexity Matrices
`
const tscomplex = require('ts-complex');const path = './test.ts'; // Finding maintainability of this file
const halstead = tscomplex.calculateHalstead(path);
console.log(halstead); // object with function name as keys and Halstead Complexity Matrices as value
`
Cyclomatic Complexity
`
const tscomplex = require('ts-complex');const path = './test.ts'; // Finding maintainability of this file
const complexity = tscomplex.calculateCyclomaticComplexity(path);
console.log(complexity); // object with function name as keys and cyclomatic complexity as value
``Maintainability = 171 - 5.2 log_2(HV) - 0.23 CC - 16.2 * log_2(SLoC)
Where,
HV = Halstead Volume
CC = Cyclomatic Complexity
SLoC = Lines of Code
We calculate Halstead Complexity Matrices and Cyclomatic Complexity for each function in the given file.
And aggregate them by two methods; considering the average and considering the maximum.
Thus, average maintainability is calculated using average halstead volume and average cyclomatic complexity.
And minimum maintainability is calculated using maximum halstead volume and maximum cyclomatic complexity.
Pull Requests are welcome!
* Anand Undavia - Anand Undavia
This project is licensed under the MIT License - see the LICENSE.md file for details