Skip to content

sumitt-wayne/code-score

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎯 code-score

Analyze JavaScript, TypeScript, and React code complexity and maintainability

npm version License: MIT Node.js

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-score

Local Installation

npm install --save-dev @sumit-wayne/code-score

πŸ“– Usage

Basic Analysis

code-score analyze ./src

Export to JSON

code-score analyze ./src -f json -o report.json

Exclude 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

MIT Β© Sumit

πŸ”— Links

πŸ™ Acknowledgments

Built with:


Made with ❀️ by Sumit for better code quality

About

Analyze JavaScript, TypeScript, and React code complexity and maintainability - A powerful CLI tool with beautiful reports

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors