@trudevlabs/complexity-checker
v1.0.0
Published
Analyzes code complexity (cyclomatic) - CLI for large projects and CI
Maintainers
Readme
complexity-checker
Analyzes code complexity (cyclomatic) - CLI for large projects and CI
Install
npm install -g complexity-checker
# or
npx complexity-check ./srcUsage
CLI
complexity-check ./srcOutput:
complexity-check: ./src
🔴 UserService.js - 35 (HIGH)
🟡 AuthController.js - 18 (MEDIUM)
🟢 utils.js - 5 (LOW)
12 files | 2 HIGH | 3 MEDIUM | 7 LOWCI - fail on HIGH
COMPLEXITY_FAIL_HIGH=1 complexity-check ./src
# exits 1 if any file has HIGH complexityAPI
const { analyzeDirectory, analyzeFile, calcComplexity } = require('complexity-checker');
// Analyze a directory
const results = analyzeDirectory('src');
// Analyze single file
const { complexity, level } = analyzeFile('src/UserService.js');
// Raw complexity from string
const score = calcComplexity('if (a) { for (;;) {} }');Custom thresholds
const results = analyzeDirectory('src', {
thresholds: { low: 10, medium: 20, high: 30 },
exclude: ['node_modules', 'dist', 'test'],
extensions: ['.js', '.ts'],
});Complexity levels
| Level | Default | Description | |---------|---------|--------------------| | LOW | ≤10 | Simple, maintainable | | MEDIUM | 11–20 | Consider refactoring | | HIGH | >20 | High risk, refactor |
License
MIT
