yamllint-rs
A YAML linter written in Rust, inspired by the Python yamllint package.
Credits
This project is a Rust implementation of yamllint by Adrien Vergé. The original yamllint serves as the reference implementation for all rules, configurations, and behavior. This Rust version aims to provide the same functionality with improved performance through parallel processing and native compilation.
Features
- Fast YAML linting powered by Rust with parallel processing
- 23 configurable rules covering formatting, content, and YAML-specific features
- Automatic fixes for fixable issues with
--fixflag - Configuration support with automatic discovery of
.yamllintfiles - Compatible with original yamllint configuration format
- Git-aware processing that respects
.gitignorefiles - Colored output with automatic detection of terminal capabilities
- Command-line interface with flexible options
- Library API for integration into Rust projects
Installation
From Source
Using Cargo
Using Docker
yamllint-rs is available as a Docker image on Docker Hub. No installation required - just run it directly:
# Lint a single file
# Lint multiple files
# Recursive directory processing
# Verbose output
# Use custom config file
# Automatically fix fixable issues
# Use specific version
Note: Replace yamllint-rs with your Docker Hub username/organization if the image is published under a different namespace (e.g., yourusername/yamllint-rs:latest).
Usage
Command Line
# Lint a single file
# Lint multiple files (processed in parallel)
# Recursive directory processing
# Verbose output
# Use custom config file
# Automatically fix fixable issues
# Set output format (standard, colored, or auto)
# Disable progress updates
# Combine options
Command-Line Options
files- YAML file(s) to lint (positional arguments)-r, --recursive- Process directories recursively-v, --verbose- Enable verbose output-c, --config <path>- Path to configuration file--fix- Automatically fix fixable issues-f, --format <format>- Output format:standard,colored, orauto(default:auto)--no-progress- Disable progress updates during processing
Configuration
yamllint-rs automatically discovers configuration files by searching for .yamllint in the current directory and parent directories. You can also specify a custom path with --config.
# Automatic discovery (searches for .yamllint in current and parent dirs)
# Explicit config file
The tool supports both the original yamllint configuration format and the native format. See the Rules.md file for detailed rule documentation.
Example .yamllint configuration:
rules:
line-length:
max: 120
indentation:
spaces: 4
ignore: |
*.template.yaml
generated/
truthy:
allowed-values:
Library API
use ;
// Process a single file
let options = ProcessingOptions ;
let processor = with_default_rules;
let result = processor.process_file?;
for in result.issues
// Process directory recursively
let processor = with_default_rules;
let issue_count = processor.process_directory?;
// Use custom configuration
use ;
if let Some = discover_config_file
// Fix mode
let processor = with_fix_mode;
processor.process_file?;
Development
# Build the project
# Build optimized release binary
# Run tests
# Run with debug output
# Format code
# Run clippy linter
# Run benchmarks
Features in Detail
Parallel Processing
yamllint-rs processes multiple files in parallel for better performance. Files are automatically processed in parallel when:
- Multiple files are specified on the command line
- Recursive directory processing finds multiple YAML files
Automatic Fixes
Many rules support automatic fixes. When using --fix, the tool will:
- Apply all fixable corrections
- Write the fixed content back to the file
- Report remaining non-fixable issues
Git Integration
When processing directories recursively, yamllint-rs respects .gitignore files using the ignore crate, automatically skipping files that would be ignored by Git.
Output Formats
- auto (default): Automatically detects terminal capabilities and NO_COLOR environment variable
- colored: Always use colored output with ANSI codes
- standard: Plain text output without colors
Supported Rules
yamllint-rs supports all 23 rules from the original yamllint. See Rules.md for complete documentation.
Enabled by Default
- braces, brackets, colons, commas, hyphens
- line-length, indentation, trailing-spaces
- comments, comments-indentation
- document-start
- empty-lines, new-lines
- new-line-at-end-of-file
- key-duplicates, anchors
- truthy
Disabled by Default
- document-end
- quoted-strings
- empty-values
- float-values
- octal-values
- key-ordering
License
MIT