How astral-sh/ruff works
Ruff is a Rust-based Python linter and formatter. A user invokes its CLI to select a check or format operation; the check workflow analyzes Python files with configurable rules, reports diagnostics, and can apply fixes, while formatting rewrites source into a consistent style. The README also documents caching, cascading configuration, stdin use, import sorting parity, and editor integrations. The graph captures those product branches and shared runtime layers; detailed internal wiring is limited because the supplied source excerpts do not include the main command implementations.
Main entry points: check.rs Check command · format.rs Format command · main.rs CLI entry · linter.rs Lint engine
Components 18
User interfaces
- CLI entry
crates/ruff/src/main.rs - Check command
crates/ruff/src/commands/check.rs - Stdin commands
crates/ruff/src/stdin.rs
Lint analysis
- Lint engine
crates/ruff_linter/src/linter.rs - Rule checks
crates/ruff_linter/src/rules - Python parser
crates/ruff_python_parser - Automatic fixes
crates/ruff_linter/src/fix - Import graph
crates/ruff_graph/src/lib.rs
Formatting
- Format command
crates/ruff/src/commands/format.rs - Formatter engine
crates/ruff_formatter/src/lib.rs
Shared runtime
- Diagnostics
crates/ruff/src/diagnostics.rs - Result output
crates/ruff/src/printer.rs - Settings resolution
crates/ruff/src/resolve.rs - File cache
crates/ruff/src/cache.rs - File access
crates/ruff_db/src/system.rs
Integrations
- Editor server
crates/ruff_server/src/server.rs
Other components
- Developer
- Python files
Connections 19
- Developer → CLI entry: invokes
- CLI entry → Check command: dispatches
- CLI entry → Format command: dispatches
- Developer → Editor server: connects editor
- Python files → Check command: provides paths
- Python files → Format command: provides paths
- Check command → Settings resolution: resolves settings
- Check command → File access: reads files
- Check command → File cache: uses cache
- Check command → Lint engine: runs analysis
- Check command → Diagnostics: collects results
- Lint engine → Python parser: parses source
- Lint engine → Rule checks: checks rules
- Check command → Automatic fixes: applies fixes
- Diagnostics → Result output: renders results
- Format command → Settings resolution: resolves settings
- Format command → File access: reads and writes
- Format command → Formatter engine: formats source
- Check command → Import graph: analyzes imports