Analyze JavaScript, TypeScript, and React code complexity and maintainability
A powerful CLI tool that analyzes your codebase and provides actionable insights on code quality, complexity, and maintainability.
- π Cyclomatic Complexity - Measure code complexity with industry-standard metrics
- π Maintainability Index - Microsoft's formula for code maintainability
- π Function Length Analysis - Identify overly long functions
- πͺ Nesting Depth Detection - Find deeply nested code blocks
- π‘ Actionable Suggestions - Get specific improvement recommendations
- π¨ Beautiful CLI Output - Color-coded, table-based reports
- π JSON Export - Machine-readable output for CI/CD integration
- β‘ Fast Analysis - Built with performance in mind
npm install -g @sumit-wayne/code-scorenpm install --save-dev @sumit-wayne/code-scorecode-score analyze ./srccode-score analyze ./src -f json -o report.jsoncode-score analyze ./src -e "**/test/**" "**/dist/**" "**/*.spec.ts"code-score analyze ./src -i "**/*.ts" "**/*.tsx"ββββββββββββββββββββββββββββββββββββββββββββββββββ
β CODE SCORE ANALYSIS REPORT β
ββββββββββββββββββββββββββββββββββββββββββββββββββ
π PROJECT SUMMARY
ββββββββββββββββββ
Files Analyzed β 36
Lines of Code β 1,628
Average Complexity β 1.2
Average Maintainability β 54.2
Risky Files β 2
π― OVERALL SCORE
ββββββββββββββββ
β
Good: 7.8/10
Complexity β 9.4/10 β Excellent
Maintainability β 5.4/10 β Fair
Code Quality β 8.1/10 β Good
Measures the number of independent paths through your code. Higher values indicate more complex, harder-to-test code.
- 1-5: β Simple, easy to test and maintain
- 6-10:
β οΈ Moderate complexity - 11-20: β High complexity, consider refactoring
- 21+: π₯ Very high, difficult to maintain
Microsoft's formula combining complexity, code volume, and lines of code. Ranges from 0-100.
- 70-100: β Good maintainability
- 50-69:
β οΈ Moderate maintainability - 0-49: β Difficult to maintain
Combines nesting depth and function length metrics to evaluate overall code structure.
You can also use code-score programmatically in your Node.js projects:
import { ProjectAnalyzer } from '@sumit-wayne/code-score';
const analyzer = new ProjectAnalyzer({
path: './src',
exclude: ['**/node_modules/**', '**/dist/**'],
});
const result = await analyzer.analyze();
console.log(`Overall Score: ${result.score.overall}/10`);
console.log(`Files Analyzed: ${result.summary.totalFiles}`);
console.log(`Critical Issues: ${result.summary.issueCount.critical}`);You can customize thresholds for different metrics:
const analyzer = new ProjectAnalyzer({
path: './src',
thresholds: {
complexity: {
low: 5,
medium: 10,
high: 20,
critical: 30,
},
nesting: {
max: 4,
},
functionLength: {
max: 50,
},
maintainability: {
good: 70,
moderate: 50,
poor: 0,
},
},
});name: Code Quality
on: [push, pull_request]
jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '18'
- run: npm install -g @sumit-wayne/code-score
- run: code-score analyze ./src -f json -o report.json
- uses: actions/upload-artifact@v2
with:
name: code-quality-report
path: report.jsonContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
MIT Β© Sumit
Built with:
- Babel for AST parsing
- Commander.js for CLI
- Chalk for terminal styling
- Ora for loading spinners
Made with β€οΈ by Sumit for better code quality