loc-rs 0.2.0

Advanced Lines of Code counter with function extraction, git integration, and parallel processing
loc-rs-0.2.0 is not a library.

loc — Advanced Lines of Code Counter

A fast, feature-rich LOC tool written in Rust.
Author: kelexine


Features

  • Minimalist Dashboard: Clean, borderless summary of all project metrics
  • Code/Comment/Blank split: Distinguishes between actual code, comments, and blank lines across dozens of languages
  • Optional Tree view: Recursive directory tree with per-file metrics (now opt-in via --tree)
  • Parallel scanning via Rayon — uses all CPU cores
  • Function extraction (⚠️ Beta) Uses Tree-sitter for robust AST parsing across 10 languages (Rust, Python, JS/TS, Go, C/C++, Java/C#, PHP, Swift, Ruby, and Nim)
  • Cyclomatic complexity estimates per function
  • Git integration — respects .gitignore and .locignore, optional git log dates
  • Interactive HTML Dashboard — beautiful visual reports (loc -e report.html)
  • Multi-format export — JSON, JSONL, CSV, HTML
  • Global Configuration via ~/.config/loc-rs/config.toml
  • GitHub Action wrapper included for CI/CD integration
  • 35+ languages supported with aliases
  • Size warnings for oversized files
  • BOM-aware binary detection for UTF-16/32 text files

Installation

From crates.io

cargo install loc-rs

From source (requires Rust ≥ 1.87.0)

git clone https://github.com/kelexine/loc-rs
cd loc-rs
cargo build --release
# Binary at: ./target/release/loc

# Install globally
cargo install --path .

Usage

loc [OPTIONS] [DIRECTORY]

Examples

loc                            # Scan current directory (summary only)
loc --tree                     # Show recursive project structure
loc -d                         # Breakdown by extension (Code/Comment/Blank)
loc -f                         # Extract functions/methods
loc -f --func-analysis         # Full complexity report
loc -t rust python             # Filter to Rust + Python only
loc -e results.json            # Export to JSON
loc -e stats.csv -f            # CSV with function data
loc -e report.html             # Generate interactive HTML dashboard
loc --warn-size 500            # Warn on files > 500 lines
loc --git-dates                # Use git log for last-modified
loc --no-parallel              # Disable parallel processing
loc --include-hidden           # Include hidden files and directories

All Flags

Flag Short Description
--detailed -d Per-extension breakdown (Code, Comment, Blank)
--tree Show recursive directory tree (hidden by default)
--binary -b Show binary files in tree
--functions -f Extract functions, methods, classes
--func-analysis Full analysis report (auto-enables -f)
--type LANG... -t Filter by language(s)
--export FILE -e Export results (.json / .jsonl / .csv / .html)
--warn-size N Warn for files exceeding N lines
--git-dates Use git log for last-modified dates
--include-hidden -H Include hidden files and directories
--no-parallel Disable Rayon parallelism

Configuration

You can persist your default arguments globally in ~/.config/loc-rs/config.toml (or your OS's equivalent standard config directory).

warn_size = 500
default_types = ["rust", "python"]
always_extract_functions = true

GitHub Action Integration

Drop loc-rs into your CI/CD pipelines to monitor complexity and line counts.

steps:
  - uses: actions/checkout@v4
  - uses: kelexine/loc-rs/.github/actions/loc-rs@main
    with:
      target_dir: .
      warn_size: 500
      functions: true

Supported Languages

Name Extensions
rust .rs
python .py .pyw .pyi
javascript .js .mjs .cjs
typescript .ts .tsx .mts
go .go
java .java
kotlin .kt .kts
c .c .h
cpp .cpp .cc .cxx .hpp
csharp .cs
swift .swift
ruby .rb
php .php
html .html .htm
css .css .scss .sass .less
shell .sh .bash .zsh .fish
markdown .md .markdown .mdx
json .json .jsonl
yaml .yml .yaml
toml .toml
xml .xml
vue .vue
svelte .svelte
scala .scala .sc
haskell .hs .lhs
elixir .ex .exs
lua .lua
dart .dart
zig .zig
nim .nim .nims

Language aliases are supported: py, js, ts, rs, rb, sh, md, yml, c++, etc.


Function Extraction Support (Now using Tree-sitter) ⚠️ Beta

Note: The Tree-sitter powered function extraction is currently in Beta (WIP). While it provides extreme accuracy, some language edge cases may still be actively refined.

Function, method, and class extraction is fully powered by robust Tree-sitter AST parsing for extreme accuracy across complex codebases.

Language Functions Methods Classes/Structs Async Decorators Docstrings
Rust ✓ (struct/impl) pub flag
Python
JavaScript/TS
Go
C/C++
Java/Kotlin/C#
PHP
Swift
Ruby
Nim public(*) flag

License

MIT © kelexine