$ show astral-sh/ruff
This repository contains the Ruff Python linter and formatter, along with the Ty Python type checker, both written in Rust. It is a monolith of several dozen crates assembled into a workspace, delivering a CLI tool, a Language Server Protocol (LSP) server, and a web playground. In production, Ruff analyzes Python source files against hundreds of lint rules from flake8, pylint, pyupgrade, and other plugins, formats code to be compatible with Black, and provides IDE features via LSP. Ty adds type checking and advanced IDE features like goto-definition and workspace symbols. The architecture is modular: a parser produces an AST, semantic analysis operates on that AST, lint rules are checked via pluggable visitors, formatting is done through an IR-based printer, and diagnostics are rendered in multiple formats (JSON, JUnit, SARIF, etc.). The LSP server reuses many of these components through a Salsa-based incremental database for caching. The repository is a model of how to structure a high-performance developer tool in Rust, with extensive test fixtures, fuzzing, and benchmarks. While primarily an application, it includes some data-like assets (test fixture corpora, ecosystem check scripts) but nothing that would classify it as a data research project.
The LLM identified 6 files worth highlighting for reuse:
Defines TextSize (u32 newtype with overflow checks) and TextRange (start/end pair) used throughout Ruff for source positions. Implements Ranged trait, serde serialization, schemars support, and auto-trait assertions. Could be extracted into any project needing byte-offset source positions.
Defines the Document enum (the intermediate representation of formatted output), including variants for text, line breaks, indentation, groups, and conditional content. The design is inspired by Rome's Formatter and is highly reusable for any code formatter needing an IR before printing.
Provides the ViolationMetadata derive macro and derive_message_formats attribute macro. These proc macros parse struct attributes to generate rule metadata (category, stable since, fix availability) and message format methods. They are central to Ruff's rule definition pattern and could be adapted for other linting frameworks.
Defines a CacheKey trait and a derive macro for generating cache keys from struct fields. Supports both Hash and a custom hashing strategy, and is used to invalidate cached results when files or settings change. The pattern is general-purpose for any incremental computation system.
A fork of Rust's annotate-snippets crate, extended to support Ruff's diagnostic output. It renders source code snippets with inline annotations (error markers, suggestions, explanations) in terminal-friendly formats. The rendering logic is cleanly separated from Ruff's internals and could be reused in other diagnostic tools.
Provides a StatementVisitor trait and implementations for traversing the AST in source order. The pattern is a classic visitor that can be extended by downstream crates without modifying the AST definition. It demonstrates a clean separation of traversal logic from analysis code.