@raketa-cloud/complexity-checker
v1.0.9
Published
Cyclomatic and cognitive complexity analyzer for JavaScript/TypeScript projects
Downloads
170
Maintainers
Readme
JavaScript Complexity Analyzer
A powerful CLI tool for analyzing cyclomatic and cognitive complexity in JavaScript/TypeScript projects. Perfect for CI/CD pipelines and code quality monitoring.
Quick Start
# Analyze current directory (default: cyclomatic complexity)
npx @raketa-cloud/complexity-checker
# Analyze cognitive complexity with custom thresholds
npx @raketa-cloud/complexity-checker ./src --type cognitive --error-threshold 15 --warning-threshold 10
# Generate detailed report
npx @raketa-cloud/complexity-checker ./src --report complexity-report.jsonFeatures
- 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 <type> | Complexity type to analyze (cyclomatic or cognitive) | cyclomatic |
| --error-threshold <number> | Error threshold for complexity | 20 |
| --warning-threshold <number> | Warning threshold for complexity | 10 |
| --report <file> | Save detailed JSON report to file | - |
Usage Examples
CI/CD Integration
# GitHub Actions example
- name: Check code complexity
run: npx @raketa-cloud/complexity-checker ./src --type cognitive --error-threshold 20Local Development
# Quick check with default settings (cyclomatic complexity)
npx @raketa-cloud/complexity-checker ./src
# Analyze cognitive complexity with strict thresholds
npx @raketa-cloud/complexity-checker ./src --type cognitive --error-threshold 15 --warning-threshold 8
# Generate 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:
{
"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 complexitywarningThreshold: Warning threshold for complexityignore: Array of glob patterns to ignore
CLI options will override configuration file settings.
Exit Codes
0- Success (no violations)1- Complexity thresholds exceeded2- Tool error (file not found, parse errors)
Output Examples
Success:
✓ No complexity threshold violations foundWarnings 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:89The format shows: [actual_complexity/threshold] function_name @ file_path:line
- 🟠 indicates warnings (complexity ≥ warning threshold but < error threshold)
- 🔴 indicates errors (complexity ≥ error threshold)
Note: All violations are collected and displayed, then exits with code 1 if any errors exist
