| Crates.io | rustedbytes-counterlines |
| lib.rs | rustedbytes-counterlines |
| version | 0.2.2 |
| created_at | 2025-08-09 17:33:09.158062+00 |
| updated_at | 2025-08-12 03:35:45.420784+00 |
| description | A high-performance, multi-language source code line counter CLI tool written in Rust |
| homepage | https://github.com/mad4j/rustedbytes-counterlines |
| repository | https://github.com/mad4j/rustedbytes-counterlines |
| max_upload_size | |
| id | 1788099 |
| size | 210,681 |
A high-performance, multi-language source code line counter written in Rust that fully implements the requirements specified in REQUIREMENTS.md.
# Clone the repository
git clone https://github.com/mad4j/rustedbytes-counterlines.git
cd rustedbytes-counterlines
# Build the project
cargo build --release
# The binary will be available at target/release/sloc
# Count lines in specific files
sloc count src/main.rs src/lib.rs
# Count with wildcards (REQ-2.2)
sloc count "src/*.rs" "tests/*.rs"
# Recursive directory traversal (REQ-2.3)
sloc count src/ -r
# Show per-file statistics and unsupported file list (only if requested)
sloc count src/ -r --details
# Read file list from stdin (REQ-2.4)
find . -name "*.rs" | sloc count --stdin
# Generate JSON report (REQ-6.1) (explicit output)
sloc report src/ -r -f json -o report.json
# Generate JSON report letting the tool auto-name the file (sloc-report.json)
sloc report src/ -r -f json
# Generate XML report (REQ-6.2)
sloc report src/ -r -f xml -o report.xml
# Generate CSV report (REQ-6.3)
sloc report src/ -r -f csv -o report.csv
# Include checksum (REQ-6.9)
sloc report src/ -r -f json -o report.json --checksum
# Show per-file statistics and unsupported file list in console (only if requested)
sloc report src/ -r -f json -o report.json --details
```bash
# If you omit -o/--output but specify -f/--format with 'count', a file named 'sloc-report.<ext>'
# is created using the configured default base name (configurable via defaults.output_file in config.toml).
# Example with count (auto export using default base name):
sloc count src/ -r -f json
Default auto-generated report file name:
sloc-report.<format>(e.g.,sloc-report.json). Configure viadefaults.output_fileinconfig.toml. Applies to bothcountandreportwhen--formatis provided without--output.
Note: By default, the tool prints only summary and language statistics. Use
--detailsto print per-file statistics and the list of unsupported files in the console output.
# Process and display statistics from a report
sloc process report.json
# Sort by different metrics (REQ-5.4)
sloc process report.json --sort logical
# Export processed results
sloc process report.json --export summary.json -f json
# Compare two reports
sloc compare report_old.json report_new.json
# Export comparison (REQ-7.4)
sloc compare report_old.json report_new.json --export comparison.json -f json
# Use custom language definitions (REQ-3.3)
sloc count src/ -r --config languages.toml
# Override language detection (REQ-3.4)
sloc count src/ --language-override "txt=python" --language-override "conf=yaml"
# Ignore preprocessor directives (REQ-4.5)
sloc count src/ --ignore-preprocessor
# Set parallel threads (REQ-9.4)
sloc count src/ -r -j 8
# Progress bar shown by default (REQ-9.5). Use --no-progress to disable
sloc count src/ -r --no-progress
Built-in support for (REQ-3.1):
Files for which no language definition is available are:
Excluded from all statistics and summaries (REQ-3.5.1)
Not included in line or language counts (REQ-3.5.2)
Listed separately in the console output and reports (REQ-3.5.3)
Rust (including nested comments)
C/C++ (with preprocessor directives)
Python (including docstrings)
JavaScript/TypeScript
Java
Go
Ruby
Shell scripts
SQL
HTML
CSS/SCSS/SASS
YAML
TOML
And more...
The tool counts four types of lines (REQ-1.1):
Reports include (REQ-6.4, REQ-6.5, REQ-6.6):
{
"reportFormatVersion": "1.0",
"generatedAt": "2024-01-15T10:30:00Z",
"files": [
{
"path": "src/main.rs",
"language": "Rust",
"totalLines": 150,
"logicalLines": 120,
"commentLines": 20,
"emptyLines": 10
}
],
"languages": [
{
"language": "Rust",
"fileCount": 10,
"totalLines": 1500,
"logicalLines": 1200,
"commentLines": 200,
"emptyLines": 100
}
],
"summary": {
"totalFiles": 10,
"totalLines": 1500,
"logicalLines": 1200,
"commentLines": 200,
"emptyLines": 100,
"languagesCount": 1
},
"checksum": "sha256_hash_here"
}
Create a languages.toml file to add or modify language definitions (REQ-3.3):
[languages.mylang]
name = "MyLanguage"
extensions = ["ml", "mli"]
single_line_comment = ["//", "#"]
multi_line_comment = [
{ start = "/*", end = "*/" },
{ start = "(*", end = "*)" }
]
nested_comments = true
preprocessor_prefix = "#"
The tool provides formatted console output with (REQ-5.1, REQ-5.2, REQ-5.3):
════════════════════════════════════════════════════════════════════════════════
Source Lines of Code (SLOC) Report
════════════════════════════════════════════════════════════════════════════════
Global Summary
────────────────────────────────────
┌──────────────┬──────────┐
│ Metric │ Value │
├──────────────┼──────────┤
│ Total Files │ 25 │
│ Total Lines │ 10,543 │
│ Logical Lines│ 8,234 │
│ Empty Lines │ 2,309 │
│ Languages │ 3 │
│ Code Density │ 78.10% │
│ Empty Ratio │ 21.90% │
└──────────────┴──────────┘
Language Summary
────────────────────────────────────────────────────────────────────────────────
┌────────────┬───────┬─────────┬──────────┬───────┬───────────┐
│ Language │ Files │ Total │ Logical │ Empty │ Density % │
├────────────┼───────┼─────────┼──────────┼───────┼───────────┤
│ Rust │ 15 │ 7,234 │ 5,890 │ 1,344 │ 81.42 │
│ TOML │ 5 │ 1,543 │ 1,234 │ 309 │ 79.97 │
│ Markdown │ 5 │ 1,766 │ 1,110 │ 656 │ 62.85 │
└────────────┴───────┴─────────┴──────────┴───────┴───────────┘
The tool provides clear error messages for (REQ-2.5):
Contributions are welcome! Please ensure that:
This project is licensed under the MIT License - see the LICENSE file for details.
This implementation fully complies with all requirements specified in REQUIREMENTS.md: