Analyzes TypeScript files for Cyclomatic Complexity, Halstead Volume, LOC and Maintainability Index
npm install marvinsconfig.json file located in the current working directory to store default thresholds and multipliers. If this file does not exist, it is automatically created with the following default values:
json
{
"cyclomatic": { "medium": 6, "high": 10 },
"maintainabilityIndex": { "low": 40, "medium": 60 },
"loc": { "medium": 30, "high": 50 },
"commentDensityMultiplier": 5
}
`
$3
#### 1. Help Command
`bash
marvins help
`
- Description:
Displays the help message with detailed information about available commands and usage examples.
#### 2. Configure Command
Marvins provides two configuration options:
##### a. Update Metric Thresholds
`bash
marvins configure -t
`
- Parameters:
- : The metric to update. Valid options are:
- cyclomatic
- maintainabilityIndex
- loc
- : The first threshold value (e.g., "medium" for cyclomatic or LOC, "low" for maintainabilityIndex).
- : The second threshold value (e.g., "high" for cyclomatic or LOC, "medium" for maintainabilityIndex).
- Example:
`bash
marvins configure -t cyclomatic 6 10
`
This updates the cyclomatic complexity thresholds to a medium value of 6 and a high value of 10.
##### b. Update Comment Density Multiplier
`bash
marvins configure -d
`
- Parameters:
- : A numeric value that updates the comment density multiplier used in the MI calculation.
- Example:
`bash
marvins configure -d 7
`
This updates the comment density multiplier to 7.
#### 3. Analyze Command
`bash
marvins analyze -f {typescript filePath}
`
- Parameters:
- {typescript filePath}: Path to the TypeScript file you wish to analyze.
- Description:
Analyzes the specified TypeScript file and displays the computed metrics, including:
- Calculated Comment Density.
- Cyclomatic Complexity.
- Halstead Volume.
- Lines of Code.
- Maintainability Index.
- Example:
`bash
marvins analyze -f src/app.ts
`
This command analyzes the src/app.ts file and outputs the analysis results.
Conclusion
Marvins Code Quality Analyzer is a powerful tool that leverages static analysis and AST traversal to provide insights into code quality. By monitoring metrics such as Cyclomatic Complexity, Halstead Volume, Lines of Code, Maintainability Index, and Comment Density, developers can better understand and improve their codebase.
For further information or assistance, simply run:
`bash
marvins help
``