LineGuard
A fast and reliable file linter that ensures proper line endings and clean formatting.
Features
- ✅ Newline Ending Check: Ensures files end with exactly one newline character
- ✅ Trailing Space Detection: Identifies and reports trailing whitespace at line ends
- 🚀 High Performance: Parallel file processing with progress indicators
- 🎨 Multiple Output Formats: Human-readable (with colors), JSON, and GitHub Actions formats
- 🔧 Configurable: Flexible configuration via CLI flags or
.lineguardrcfiles - 🔄 Auto-fix: Automatically fix issues with
--fixflag - 📁 Smart File Discovery: Glob patterns, recursive directory scanning, stdin support
- 🎯 Selective Checks: Disable specific checks via CLI flags
- 💾 Memory Efficient: Streaming support for large files (>10MB)
- 🛡️ Robust Error Handling: Graceful handling of permission errors
- 🔍 Binary File Detection: Automatically skips binary files
- 👁️ Hidden Files: Checks hidden files by default (use
--no-hiddento skip) - 🚫 Ignore Patterns: Skip files/directories with glob patterns
- 📝 File Extension Filtering: Check only specific file types
- 🔀 Git Integration: Check only files changed between commits
Installation
From Crates.io
From GitHub Releases
Download pre-built binaries from the latest release:
# Linux/macOS
|
# Windows
# Download the .zip file and extract lineguard.exe to a directory in your PATH
From Source
Shell Command Alternative
If you prefer not to install LineGuard, you can achieve similar functionality using standard Unix tools:
# Basic check for trailing spaces and missing newlines
# Fix issues automatically
# Check files changed in git
| while ; do [ && { && ; [ && ; }; done
See Shell Alternatives section for more examples.
Usage
Basic Usage
# Check a single file
# Check multiple files
# Check with glob pattern
# Check all files in directory
Command-Line Options
)
)
)
)
)
Advanced Usage
# Fix issues automatically
# Preview fixes without applying
# Ignore specific patterns
# Check only specific file types
# Use custom config file
# Disable specific checks
# Pipe files from other commands
|
# Check files changed in the last commit
# Check files changed between specific commits
# Check files changed since a tag
# Combine with other options
Output Examples
Human-Readable Format (Default)
✗ src/main.rs
- Missing newline at end of file
- Line 45: Trailing spaces found
✓ src/lib.rs
Summary: 1 file with issues, 2 total issues found
JSON Format
GitHub Actions Format
Configuration File
LineGuard supports configuration files to customize its behavior. Create a .lineguardrc file in your project root (see .lineguardrc.example for reference):
# .lineguardrc
[]
= true # Check for proper newline at end of file
= true # Check for trailing spaces
# Ignore patterns (glob format)
= [
"**/target/**",
"**/.git/**",
"**/node_modules/**",
"*.generated.*",
]
# File extensions to check (default: all text files)
= [
"rs", "toml", "md", "txt",
"js", "ts", "jsx", "tsx",
"py", "go", "java", "c", "cpp", "h", "hpp",
"yml", "yaml", "json", "xml",
]
Configuration files are searched in the following order:
- Path specified with
--configflag .lineguardrcin the current directory.lineguardrcin parent directories (up to the root)
CLI flags always override configuration file settings.
Exit Codes
0- Success, no issues found1- Issues found in checked files2- Error in command-line arguments3- File access or I/O error4- Configuration error
Development
This project follows strict Test-Driven Development (TDD) practices. See IMPLEMENTATION_PLAN.md for development guidelines.
Building
Testing
LineGuard uses comprehensive testing with dependency injection patterns for better testability.
Running Tests
# Run all tests
# Run only unit tests (fast)
# Run only integration tests
# Run tests for a specific module
# Run tests with output
Test Coverage
# Install cargo-tarpaulin
# Generate coverage report (HTML)
# Generate coverage report (stdout)
# Check coverage for all tests
Current coverage targets:
- Overall: 90%+
- Core modules (checker, reporter): 85%+
- Utility modules: 80%+
Test Architecture
The codebase uses dependency injection and mock implementations:
// Using MockFileSystem for testing file operations
use MockFileSystem;
let mut fs = new;
fs.add_file;
// Using MockOutput for testing output operations
use MockOutput;
let mut output = new;
reporter.report_to?;
assert_eq!;
Code Quality
Shell Alternatives
While LineGuard provides superior performance and features, you can achieve similar basic functionality using standard Unix tools. These examples use find, grep, sed, and other common utilities.
Basic Checks
# Check single file for issues
# Check all text files in current directory
# Recursive check with multiple extensions
Fix Issues
# Remove trailing spaces from files
# Add missing newlines
# Fix both issues at once
# Apply fixes to all matching files
Git Integration
# Check files changed in last commit
| while ; do
[ && {
&&
[ &&
}
done
# Check files changed between branches
| while ; do
[ &&
done
# Check staged files before commit
| while ; do
[ && {
&& { ; ; }
[ && { ; ; }
}
done
Advanced Examples
# Parallel processing with GNU parallel (if installed)
| |
# Generate report similar to LineGuard
Shell Function for .bashrc/.zshrc
Add this function to your shell configuration for easy access:
# Usage:
# lineguard_check "*.txt" # Check .txt files in current directory
# lineguard_check "*.rs" -r # Recursively check .rs files
Comparison
| Feature | LineGuard | Shell Commands |
|---|---|---|
| Performance | Fast (parallel Rust) | Slower (sequential bash) |
| Binary file detection | Automatic | Manual with file command |
| Progress bar | Yes (for large sets) | No |
| Configuration file | Yes (.lineguardrc) | No |
| Output formats | Human, JSON, GitHub | Basic text only |
| Cross-platform | Yes | Unix/Linux/macOS only |
| Memory usage | Efficient streaming | Depends on file size |
| Error handling | Comprehensive | Basic |
| Installation | Required | Uses built-in tools |
Choose LineGuard for production use and comprehensive checking. Use shell commands for quick checks or when installation is not possible.
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.