Skip to content

ibrahimcesar/lucent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

15 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Lucent ๐Ÿ’Ž

Crystal clear code insights

Lucent is a fast, extensible code metrics analyzer built in Rust. It helps you understand code quality, complexity, and maintainability across multiple programming languages.

โœจ Features

  • ๐Ÿš€ Fast - Rust-powered analysis for large codebases
  • ๐ŸŒ Multi-language - 21+ languages supported (Rust, Python, JS/TS, Go, Java, C/C++, C#, Ruby, PHP, Swift, Kotlin, Dart, Scala, Elixir, Haskell, Clojure, Lua, Shell, SQL)
  • ๐Ÿ“Š 70+ Metrics Catalog - Comprehensive roadmap from basic LOC to advanced SPACE metrics
  • ๐Ÿ’Ž Beautiful Output - Rich colors, emojis, and ASCII charts in terminal, JSON, Markdown, and CSV exports
  • ๐Ÿ” Code Quality - Shannon entropy, code density, comment ratio & quality analysis, TODO/FIXME/HACK detection
  • ๐Ÿ‘ƒ Code Smells - Automatic detection of long functions, long parameter lists, deep nesting, and magic numbers
  • ๐Ÿ“ˆ Maintainability Index - Microsoft MI formula with A-F letter grades for code maintainability assessment
  • ๐Ÿ“Š Visual Analytics - ASCII bar charts for complexity and nesting depth visualization
  • ๐ŸŽจ Multiple Outputs - Pretty terminal, JSON, Markdown, CSV, and interactive HTML reports with charts
  • ๐ŸŒ Interactive HTML Reports - Beautiful, self-contained reports with Chart.js visualizations, dark mode, and export capabilities
  • โš™๏ธ Configurable - Metric profiles and thresholds via .lucent.toml
  • โšก CI/CD Ready - GitHub Actions workflows for PR analysis, quality gates, and automated testing

๐Ÿšง Status

Phase 1 Complete! โœ… - Core architecture implemented and working.

Current version: 0.1.0-alpha

What's Working Now:

  • โœ… File scanning with .gitignore support
  • โœ… 21+ language detection
  • โœ… Line counting (code, comments, blanks)
  • โœ… Shannon entropy calculation
  • โœ… Cyclomatic complexity
  • โœ… Cognitive complexity (NEW!)
  • โœ… Nesting depth detection
  • โœ… Function counting & length metrics
  • โœ… Comment quality analysis (NEW!)
  • โœ… Code smells detection (NEW!)
    • Long functions (>50 lines)
    • Long parameter lists (>5 params)
    • Deep nesting (>4 levels)
    • Magic numbers
  • โœ… Maintainability Index (NEW!)
    • Microsoft MI formula (0-100 scale)
    • Letter grades (A-F)
    • Per-language and overall metrics
  • โœ… TODO/FIXME/HACK detection
  • โœ… Beautiful terminal output with colors & emojis
  • โœ… ASCII complexity visualizations (NEW!)
  • โœ… JSON export
  • โœ… Markdown report generation (NEW!)
  • โœ… CSV export (NEW!)
  • โœ… Interactive HTML Reports (NEW!)
    • Chart.js visualizations
    • Dark/light mode toggle
    • Print/PDF export
    • CSV export from browser
    • Responsive design
  • โœ… Configuration System (NEW!)
    • .lucent.toml file support
    • Hierarchical config loading (project โ†’ user โ†’ defaults)
    • Threshold customization for all metrics
    • Ignore patterns (.lucentignore + .gitignore)
    • Language-specific overrides
    • Quality gates configuration
  • โœ… Snapshot & History Tracking (NEW!)
    • Save snapshots with lucent snapshot save
    • List all snapshots with lucent snapshot list
    • Compare snapshots with trend analysis and quality score
    • Git integration (commit hash, branch, author, dirty state)
    • Automatic cleanup with retention policy
    • JSON storage in .lucent/history/
  • โœ… Threshold Checking & Quality Gates (NEW!)
    • Exit code enforcement for CI/CD pipelines
    • --max-complexity, --max-nesting, --min-maintainability
    • --max-function-length, --max-code-smells, --max-todos
    • --fail-on-warning flag to treat warnings as errors
    • Warning vs Error severity levels
    • Per-language thresholds - Set different standards for each language
  • โœ… GitHub Actions workflows (NEW!)
    • PR analysis with automated comments
    • Quality gate enforcement
    • Diff-mode for changed files only
    • Multi-platform CI/CD pipeline
  • โœ… Git Hooks (NEW!)
    • lucent init --hooks to install pre-commit hooks
    • Automatic quality checks on staged files
    • Prevent commits that fail quality gates
    • Template-based hook generation
  • โœ… Quality Badges (NEW!)
    • lucent badge to generate README badges
    • Shields.io URLs (zero infrastructure!)
    • Markdown and SVG formats
    • Show off your code quality
  • โœ… Plugin System (NEW!)
    • Extensible architecture for custom analyzers
    • Built-in regex plugin (default)
    • Plugin API with priority-based selection
    • Ready for tree-sitter integration
    • See Plugin Developer Guide
  • โœ… 65 tests passing (50 unit + 14 integration + 1 doc)

๐ŸŽฏ Roadmap

Phase 1: Foundation โœ… COMPLETE

  • Basic file traversal and language detection
  • Lines of code counting (code, comments, blanks)
  • Shannon entropy calculation
  • Support for 13+ languages
  • Beautiful terminal output
  • TODO/FIXME/HACK tracking

Phase 2: Core Metrics ๐Ÿšง IN PROGRESS

  • Cyclomatic complexity โœ…
  • Nesting depth detection โœ…
  • Function/method counting & length โœ…
  • Comment quality analysis โœ…
  • Git-based metrics (commit size, velocity, churn)
  • GitHub Action for PR analysis (automated comments)
  • Expanded language support (21+ languages) โœ…

Phase 3: Advanced Features ๐Ÿšง IN PROGRESS

  • Cognitive complexity โœ…
  • Code smell detection โœ…
    • Long functions
    • Long parameter lists
    • Deep nesting
    • Magic numbers
  • Maintainability index โœ…
  • Halstead metrics
  • HTML reports โœ…
  • Configuration system (.lucent.toml) โœ…
    • Threshold customization
    • Ignore patterns
    • Language-specific overrides
    • Quality gates configuration
  • Snapshot & history tracking โœ…
    • Save/load snapshots
    • Compare snapshots
    • Git integration
    • Trend analysis
  • Threshold checking & quality gates โœ…
    • Exit code enforcement
    • CLI threshold flags
    • Warning vs Error severity
    • Fail-on-warning mode

Phase 4: Enterprise & Extensibility โณ PLANNED

  • SPACE metrics (DORA)
  • Team Topologies indicators
  • Plugin system (tree-sitter based)
  • Interactive TUI mode
  • Change coupling analysis

๐Ÿ“Š Full Metrics Catalog

See ROADMAP.md for the complete catalog of 70+ metrics organized by phase, including:

  • Traditional metrics (Cyclomatic, Cognitive, Halstead, Maintainability Index)
  • Git-based metrics (Commit velocity, Code churn, Entropy delta, Hotspot analysis)
  • SPACE metrics (Nicole Forsgren/DORA)
  • Team Topologies indicators (Cognitive load, Module complexity)
  • Security metrics (Secret patterns, Unsafe code detection)
  • 6 metric profiles: minimal, standard, comprehensive, team_lead, security, performance

๐ŸŽ“ Supported Languages

Currently Supported (21+) โœ…

Tier 1: ๐Ÿฆ€ Rust โ€ข ๐Ÿ Python โ€ข ๐Ÿ“œ JavaScript โ€ข ๐Ÿ’  TypeScript โ€ข ๐Ÿน Go โ€ข โ˜• Java โ€ข โš™๏ธ C++ โ€ข ๐Ÿ”ง C โ€ข #๏ธโƒฃ C# โ€ข ๐Ÿ’Ž Ruby โ€ข ๐Ÿ˜ PHP โ€ข ๐Ÿฆ… Swift โ€ข ๐ŸŽฏ Kotlin

Tier 2: ๐ŸŽฏ Dart โ€ข ๐Ÿ”ด Scala โ€ข ๐Ÿ’ง Elixir โ€ข ฮป Haskell โ€ข ๐ŸŒ€ Clojure โ€ข ๐ŸŒ™ Lua โ€ข ๐Ÿš Shell โ€ข ๐Ÿ—„๏ธ SQL

Planned Expansion (Phase 3+)

Tier 3: Zig, F#, Julia, OCaml, Nim, R, MATLAB, Perl, Objective-C

See LANGUAGES.md for details and ROADMAP.md for language expansion plans.

๐Ÿ”ง Installation

# Not yet published to crates.io
# For now, build from source:
git clone https://github.com/ibrahimcesar/lucent
cd lucent
cargo build --release

# Run from project directory
cargo run -- .

# Or install locally
cargo install --path .
lucent .

๐Ÿš€ Usage

Quick Start

# Initialize project (install git hooks)
lucent init

# Analyze current directory
lucent .

# Analyze specific path
lucent src/

# Output as JSON
lucent --format json

# Output as interactive HTML report
lucent --format html > report.html

# Output as Markdown
lucent --format markdown > report.md

# Output as CSV
lucent --format csv > metrics.csv

# Verbose output with per-file details
lucent --verbose --per-file

# Get help
lucent --help

Git Hooks

Install pre-commit hooks to run Lucent automatically before each commit:

# Install git pre-commit hook
lucent init --hooks

# Create configuration file
lucent init --config

# Your commits will now be checked for quality issues!

The pre-commit hook will:

  • โœ… Analyze all staged source files
  • โœ… Run quality gates based on your .lucent.toml configuration
  • โœ… Block commits that fail quality checks (can bypass with --no-verify)

Quality Badges

Generate badges to show off your code quality in README:

# Generate markdown badge (default)
lucent badge

# Output: ![Code Quality](https://img.shields.io/badge/code_quality-A-brightgreen)

# Just the URL
lucent badge --type url

# Generate SVG file
lucent badge --type svg --output badge.svg

Badge grades are based on Maintainability Index:

  • A (90-100): Excellent maintainability
  • B (80-89): Good maintainability
  • C (70-79): Moderate maintainability
  • D (60-69): Difficult to maintain
  • F (0-59): Extremely difficult to maintain

Quality Gates for CI/CD

# Quality gates (exit code 1 if thresholds violated)
lucent --max-complexity 10.0 --min-maintainability 70.0

# Combine multiple thresholds
lucent --max-complexity 15.0 --max-nesting 4.0 --max-todos 10

# Fail on warnings (treat warnings as errors)
lucent --max-function-length 50.0 --fail-on-warning

# Load thresholds from .lucent.toml configuration file
lucent  # Auto-discovers .lucent.toml in current/parent directories

# Use custom config file
lucent --config-file path/to/my-config.toml

# CLI flags override config file settings
lucent --max-complexity 20.0  # Overrides value from .lucent.toml

Configuration File

Create a .lucent.toml file in your project root to set default thresholds:

[thresholds]
max_cyclomatic_complexity = 15.0
max_nesting_depth = 4.0
min_maintainability_index = 65.0
max_function_length = 50

[quality_gates]
fail_on_complexity = true
fail_on_nesting = true
warn_only = false

# Per-language overrides
[languages.rust]
max_cyclomatic_complexity = 12.0
max_nesting_depth = 3.0

See examples/lucent-thresholds.toml for a complete example.


### Example Output

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” ๐Ÿ’Ž Lucent Analysis Results โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Š Summary Total Files: 9 Total Lines: 1342 Code Lines: 939 Comment Lines: 189 Avg Entropy: 4.68 Avg Complexity: 12.3 Avg Nesting: 4.2 Total Functions: 72 Avg Func Length: 14.1

๐Ÿ”– Code Markers TODOs: 3 FIXMEs: 1

๐ŸŒ By Language

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ โ”‚ Language โ”‚ Files โ”‚ Lines โ”‚ Code โ”‚ Comments โ”‚ Blanks โ”‚ Complexity โ”‚ Nesting โ”‚ Entropy โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ ๐Ÿฆ€ Rust โ”‚ 9 โ”‚ 1342 โ”‚ 939 โ”‚ 189 โ”‚ 214 โ”‚ 12.3 โ”‚ 4.2 โ”‚ 4.68 โ”‚ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

๐Ÿ’ก Insights โš ๏ธ High complexity: 12.3 (consider refactoring) โš ๏ธ Deep nesting: 4.2 levels (reduce nesting) โœ“ Short functions: 14.1 lines avg (good modularity) โœ“ Well documented: 14.1% comments โš ๏ธ Mediocre comment quality: 40% (add more context) ๐Ÿ“Š High entropy: 4.68 (information dense) ๐Ÿ“ˆ Code density: 70.0%

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”


## ๐Ÿค– CI/CD Integration

Lucent comes with production-ready GitHub Actions workflows for automated code analysis.

### Quick Start

1. **Copy workflows to your repository**:
   ```bash
   mkdir -p .github/workflows
   cp .github/workflows/lucent-*.yml .github/workflows/
  1. Push and create a PR - Lucent will automatically analyze your code!

Available Workflows

๐Ÿ’Ž Full PR Analysis

Analyzes entire codebase on every pull request:

  • Posts detailed metrics as PR comment
  • Enforces quality gate thresholds
  • Generates markdown and JSON reports

Quality Gates (configurable):

  • โŒ Fails if complexity > 20.0
  • โŒ Fails if nesting depth > 5.0
  • โš ๏ธ Warns if comment quality < 30%

๐Ÿ’Ž Diff Analysis (Recommended)

Analyzes only changed files for faster feedback:

  • Focused analysis on your modifications
  • Per-file metrics in PR comment
  • Ideal for large codebases

๐Ÿ“ˆ Trend Comparison

Compares PR metrics with base branch:

  • Tracks quality improvements/regressions
  • Calculates metric deltas with percentages
  • Provides quality score (0-100)
  • Visual trend indicators (โœ… โžก๏ธ โŒ)
  • 90-day historical tracking

๐Ÿงช CI Pipeline

Comprehensive testing and building:

  • Multi-platform (Linux, macOS, Windows)
  • Automated testing and linting
  • Code coverage reporting
  • Release binary builds

Example PR Comment

Lucent PR Comment

## ๐Ÿ’Ž Lucent Code Analysis Report

### ๐Ÿ“Š Summary
| Metric | Value |
|--------|-------|
| Total Files | 15 |
| Average Complexity | 8.2 |
| Quality Score | โœ… PASS |

### ๐Ÿ“Š Complexity Visualization
  ๐Ÿฆ€ Rust     12.5 โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘
  ๐Ÿ Python    6.3 โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘

Customize Thresholds

Edit .github/workflows/lucent-pr-analysis.yml:

# Strict quality gates
COMPLEXITY_THRESHOLD=10.0
NESTING_THRESHOLD=3.0
COMMENT_QUALITY_THRESHOLD=0.5

See .github/workflows/README.md for complete documentation.

๐Ÿ“š Documentation

Comprehensive Guides

  • ๐Ÿ“ˆ Maintainability Index Guide - NEW!

    • Understand the MI formula and scoring
    • Learn how to interpret A-F letter grades
    • Fine-tune thresholds for your organization
    • Practical strategies for improving your scores
    • Real-world examples and case studies
  • ๐Ÿ“Š Metrics Explained

    • Deep dive into all metrics
    • Shannon Entropy explained
    • Complexity metrics guide
    • Comment quality analysis
  • ๐Ÿ”ง Configuration

    • Quality gate customization
    • Threshold recommendations by project type
    • CI/CD integration patterns
  • .github/workflows/README.md

    • Complete GitHub Actions documentation
    • Workflow customization examples
    • Quality gate configuration

๐Ÿค Contributing

Contributions are welcome! This project is in early stages, and we're building the foundation.

How to contribute:

  • ๐Ÿ› Report bugs or suggest features via Issues
  • ๐Ÿ’ป Submit PRs for bug fixes or new features
  • ๐Ÿ“ Improve documentation
  • ๐Ÿ”Œ Create language plugins (once plugin system is ready)

๐Ÿ“ License

MIT

๐Ÿ™ Acknowledgments

Inspired by:


Status: ๐Ÿšง Pre-alpha - Core architecture in development

Star โญ this repo to follow development!

About

๐Ÿ’Ž Lucent is a fast, extensible code metrics analyzer built in Rust. It helps you understand code quality, complexity, and maintainability across multiple programming languages.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors