Cyclomatic and cognitive complexity analyzer for JavaScript/TypeScript projects
npm install @raketa-cloud/complexity-checkerA powerful CLI tool for analyzing cyclomatic and cognitive complexity in JavaScript/TypeScript projects. Perfect for CI/CD pipelines and code quality monitoring.
``bashAnalyze current directory (default: cyclomatic complexity)
npx @raketa-cloud/complexity-checker
Features
- Single Complexity Focus: Analyze either cyclomatic or cognitive complexity
- CI/CD Ready: Exit codes for pipeline integration
- Configurable Thresholds: Custom warning and error levels
- Smart Filtering: Ignore patterns with glob support
- Configuration File: JSON-based project configuration
- Detailed Reports: JSON output for tracking over time
- Fast Analysis: Babel-powered AST parsing
- TypeScript Support: Analyze .js, .jsx, .ts, .tsx files
CLI Options
| Option | Description | Default |
|--------|-------------|---------|
|
--type | Complexity type to analyze (cyclomatic or cognitive) | cyclomatic |
| --error-threshold | Error threshold for complexity | 20 |
| --warning-threshold | Warning threshold for complexity | 10 |
| --report | Save detailed JSON report to file | - |Usage Examples
$3
`yaml
GitHub Actions example
- name: Check code complexity
run: npx @raketa-cloud/complexity-checker ./src --type cognitive --error-threshold 20
`$3
`bash
Quick check with default settings (cyclomatic complexity)
npx @raketa-cloud/complexity-checker ./srcAnalyze cognitive complexity with strict thresholds
npx @raketa-cloud/complexity-checker ./src --type cognitive --error-threshold 15 --warning-threshold 8Generate report for tracking
npx @raketa-cloud/complexity-checker ./src --report "reports/complexity-$(date +%Y%m%d).json"
`Configuration File
Create a
complexity.config.json file in the root of your analyzed directory:`json
{
"type": "cognitive",
"errorThreshold": 25,
"warningThreshold": 15,
"ignore": [
"/test/",
"*/.spec.js",
"/vendor/"
]
}
`Configuration options:
-
type: Complexity type to analyze ("cyclomatic" or "cognitive")
- errorThreshold: Error threshold for complexity
- warningThreshold: Warning threshold for complexity
- ignore: Array of glob patterns to ignoreCLI options will override configuration file settings.
Exit Codes
-
0 - Success (no violations)
- 1 - Complexity thresholds exceeded
- 2 - Tool error (file not found, parse errors)Output Examples
Success:
`
ā No complexity threshold violations found
`Warnings and Errors:
`
š [12/10] parseComplexConfig @ src/utils/parser.js:45
š [16/10] renderRows @ src/components/DataTable.js:23
š“ [25/20] processData @ src/legacy/processor.js:156
š“ [28/20] convertLegacyData @ src/legacy/converter.js:89
`The format shows:
[actual_complexity/threshold] function_name @ file_path:line`Note: All violations are collected and displayed, then exits with code 1 if any errors exist