README
ΒΆ
Code Metrics Analyzer
A fast, multi-language code metrics analyzer written in Go. Similar to tools like cloc, tokei, and VSCode Counter, but with modern features and beautiful output formatting.
π€ Generated with AI assistance.
Features
- π 50+ Programming Languages Supported - From Go to Python, JavaScript to Rust, and many more
- π Detailed Metrics - Lines of code, comments, blank lines, and percentages
- π¨ Beautiful Output - Colored terminal output or clean markdown reports
- π Smart File Detection - Automatic language detection based on file extensions
- π Flexible Analysis - Choose specific languages or analyze everything
- π Visual Charts - Unicode bar charts showing language distribution
- β‘ Fast & Efficient - Parallel processing for large codebases
- π Multiple Output Formats - Terminal tables or markdown reports
Installation
go install codeberg.org/pfeiffer/codemetrics@latest
Prerequisites
- Go 1.16 or higher
Usage
Basic Usage
# Analyze current directory
./metrics
# Analyze specific directory
./metrics -path /path/to/project
# Generate markdown report
./metrics -output report.md
Command-Line Options
| Flag | Description | Default |
|---|---|---|
-path |
Directory to analyze | . (current) |
-output |
Output file path (e.g., report.md) |
stdout |
-format |
Output format: terminal or markdown |
terminal |
-lang |
Comma-separated languages (e.g., Go,Python,JavaScript) |
Common languages |
-all |
Analyze all supported languages | false |
-files |
Show individual file statistics | false |
-sort |
Sort by: code, comment, blank, total, name |
code |
-exclude |
Comma-separated directories to exclude | vendor,.git,node_modules,dist,build |
-no-color |
Disable colored terminal output | false |
Examples
Analyze Go and Python Files
./metrics -lang "Go,Python"
Generate Detailed Markdown Report
./metrics -all -files -output project-metrics.md
Analyze Full-Stack Project
./metrics -lang "JavaScript,TypeScript,HTML,CSS,Go,SQL" -files
Sort by Comment Lines
./metrics -files -sort comment
Output Examples
Terminal Output
================================================================================
Multi-Language Code Metrics Analyzer
================================================================================
Language Summary:
============================================================================
Language Files Total Code Comments Blank Code % Comment %
------------ ------ ---------- ---------- ---------- -------- -------- ----------
Go 142 28,453 22,156 3,421 2,876 77.9% 12.0%
Python 89 15,234 11,892 1,856 1,486 78.1% 12.2%
JavaScript 67 12,456 9,234 1,789 1,433 74.1% 14.4%
TOTAL 298 56,143 43,282 7,066 5,795 77.1% 12.6%
============================================================================
Markdown Report
# Code Metrics Report
## Summary Statistics
- **Total Files:** 298
- **Lines of Code:** 43,282 (77.1%)
- **Comment Lines:** 7,066 (12.6%)
## Top Languages by Lines of Code
Go βββββββββββββββββββββββββββββββββββββββ 51.2% 22,156 lines
Python βββββββββββββββββββββββββββββββββββββββ 27.5% 11,892 lines
JavaScript βββββββββββββββββββββββββββββββββββββββ 21.3% 9,234 lines
Supported Languages
Web Technologies
- HTML, CSS, SCSS/Sass
- JavaScript, TypeScript
- Vue, Svelte
- JSON, XML
Systems Programming
- C, C++, Rust, Zig
- Go, Swift, Kotlin
- Assembly
Scripting Languages
- Python, Ruby, Perl
- Shell/Bash, PowerShell
- Lua, R, Julia
JVM Languages
- Java, Scala, Groovy
- Clojure, Kotlin
Functional Languages
- Haskell, OCaml, F#
- Erlang, Elixir
- Lisp, Scheme
Configuration & Data
- YAML, TOML, JSON
- Dockerfile, Makefile
- SQL
And Many More!
C#, Dart, PHP, MATLAB, Fortran, Pascal, Ada, COBOL, LaTeX, Vim Script, and more...
Features in Detail
Smart Comment Detection
- Single-line comments (
//,#,--) - Multi-line block comments (
/* */,""" """) - Nested comments (Rust, Swift, Kotlin)
- Language-specific patterns
Accurate Line Counting
- Distinguishes between code, comments, and blank lines
- Handles mixed lines (code + inline comments)
- Respects language-specific syntax
Performance
- Efficient parallel directory traversal
- Minimal memory footprint
- Fast processing even for large codebases
License
This project is licensed under the MIT License. See the LICENSE file for details. SOFTWARE.
Acknowledgments
Inspired by excellent tools like:
- cloc - Count Lines of Code
- tokei - Fast code statistics
- VSCode Counter - VSCode extension for code metrics
Documentation
ΒΆ
There is no documentation for this package.
Click to show internal directories.
Click to hide internal directories.