@sumit-wayne/code-score-cli
v1.0.0
Published
Analyze JavaScript, TypeScript, and React code complexity and maintainability
Maintainers
Readme
🎯 code-score
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.
✨ Features
- 📊 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
🚀 Installation
Global Installation (Recommended)
npm install -g @sumit-wayne/code-scoreLocal Installation
npm install --save-dev @sumit-wayne/code-score📖 Usage
Basic Analysis
code-score analyze ./srcExport to JSON
code-score analyze ./src -f json -o report.jsonExclude Patterns
code-score analyze ./src -e "**/test/**" "**/dist/**" "**/*.spec.ts"Include Only Specific Files
code-score analyze ./src -i "**/*.ts" "**/*.tsx"📊 Example Output
╔════════════════════════════════════════════════╗
║ 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🎨 Metrics Explained
Cyclomatic Complexity
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
Maintainability Index
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
Code Quality Score
Combines nesting depth and function length metrics to evaluate overall code structure.
🔧 Programmatic API
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}`);🛠️ Configuration
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,
},
},
});📝 CI/CD Integration
GitHub Actions
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.json🤝 Contributing
Contributions 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
📄 License
MIT © Sumit
🔗 Links
🙏 Acknowledgments
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
