How ewhauser/shuck works
1. Repository shape
- This is a Rust monorepo centered on the shuck CLI binary, with reusable analysis crates underneath it.
- The top-level product is a shell script linter/formatter, but the repo also contains docs generation, benchmarks, fuzzing targets, and a website that publishes rule/reference content.
2. User-facing entry point
- The executable lives in crates/shuck, with subcommands for check, format, clean, and stdin-oriented formatting/checking flows.
- That crate is the orchestration layer: it handles args/config, file discovery, cache lookup, and dispatches into parsing, analysis, linting, and formatting pipelines.
3. Source acquisition and discovery
- Input comes from paths, directories, or stdin.
- Directory runs use built-in discovery rules based on file extensions and shebangs, while respecting ignore files and skipping common vendor/cache directories.
- This discovery boundary matters because everything downstream assumes a set of shell-script sources, not arbitrary text files.
4. Parsing layer
- crates/shuck-parser is the front line for shell syntax. It tokenizes and parses shell scripts into syntax structures, with dedicated parsers for words, commands, redirects, heredocs, and arithmetic.
- It also has fuzz targets and corpus-style tests, indicating the parser is treated as a core correctness boundary.
- The parser is dialect-aware enough to support bash/sh/mksh/zsh-oriented constructs used later by semantic and lint logic.
5. Syntax and indexing support
- crates/shuck-ast defines shared syntax data types such as AST nodes, names, spans, and tokens.
- crates/shuck-indexer builds auxiliary indexes over source text: line maps, region maps, and comment indexes.
- These indexes are used by diagnostics, suppression handling, and comment-aware formatting/lint logic to translate parser structures back to precise source locations.
6. Semantic analysis layer
- crates/shuck-semantic builds higher-level models from parsed syntax: bindings, declarations, scopes, references, control-flow, call graph, dataflow, runtime/contract facts, and zsh option state.
- This is the main “understanding” layer between syntax and rules. It turns shell code into analyzable program facts instead of raw ASTs.
- Many lint rules consume these semantic facts rather than walking syntax directly, which keeps rule logic focused on meaning rather than parsing details.
7. Lint engine and rules
- crates/shuck-linter is organized around rule families: correctness, style, performance, portability, and security.
- The linter collects facts, applies rule selectors/rule sets, and emits violations with severity, code, and span information.
- Suppression support is integrated, including native shuck: directives and ShellCheck-compatible shellcheck disable=SCxxxx comments, with a mapping layer for compatibility.
- The large fixture and snapshot sets under resources/test and src/rules/*/snapshots show that each rule is validated as a small, repeatable analysis unit.
8. Formatting pipeline
- crates/shuck-formatter is a separate subsystem from linting, with its own formatting model, context, streaming logic, comment handling, simplification passes, and output word/command formatting.
- It consumes parsed shell structures and formatting options, then emits rewritten scripts while preserving or intentionally adjusting comments, redirects, and whitespace.
- The formatter has oracle fixtures and dedicated tests, which suggests its correctness boundary is “textual equivalence and formatting invariants,” not just AST validity.
9. Caching and incremental behavior
- crates/shuck-cache provides shared caching primitives used by the CLI to avoid re-linting unchanged files.
- The README makes clear the cache is per-file, shared across runs, and stored outside the project tree by default.
- Architecturally, cache lookup sits between discovery and analysis, allowing the tool to short-circuit expensive parse/semantic/lint work on stable inputs.
10. Diagnostics and output
- Violations are converted into user-facing diagnostics with code frames or concise one-line output.
- The output layer is part of the CLI, but the data comes from the linter’s violation model plus source indexes/spans, which is why precise span handling is a key cross-cutting concern.
- Exit codes distinguish clean runs, lint/parse failures, and runtime/IO failures.
11. Validation and quality gates
- The repo uses cargo tests, snapshot tests, fuzz targets, benchmark suites, and large-corpus conformance testing.
- The scripts/, specs/, and docs/rules/ directories indicate a strong documentation-and-spec boundary: rules are documented as first-class artifacts and validated against real-world shell corpora.
- CI workflows cover test, fuzz, release, website publishing, and tag/release automation.
12. Website and published rule docs
- website/ is a separate Next.js app that renders rule documentation and general project docs from the generated rule metadata/content.
- website/scripts/generate-rules.ts and the docs/rules/*.yaml files suggest a docs-generation flow from rule definitions into the public site.
- This is an external-facing read model of the linter’s rules, distinct from the Rust analysis runtime.
13. Overall data flow
- The main runtime flow is: discover input → read source → parse → build indexes/semantic facts → apply rules and suppressions → optionally format/fix → emit diagnostics or rewritten text.
- The main architecture boundary is between syntactic parsing and semantic/rule analysis; the CLI orchestrates, but most real logic is isolated in reusable crates.
Main entry points: shuck-linter Linter · shuck-parser Parser · shuck-indexer Indexes · shuck-formatter Formatter
Components 18
Rust runtime
Main CLI pipeline and reusable analysis crates
- shuck CLI · Entry point for check, format, clean, stdin flows, config, and exit codes
crates/shuck - Discovery · Finds shell-script inputs from paths, directories, stdin, shebangs, extensions, and ignore rules
crates/shuck/src/discover.rs - Cache · Per-file cache used to skip unchanged analysis work
crates/shuck-cache - Parser · Tokenizes and parses shell syntax including words, commands, redirects, heredocs, and arithmetic
crates/shuck-parser - AST · Shared syntax types for nodes, names, spans, and tokens
crates/shuck-ast - Indexes · Line, region, and comment indexes for span resolution and comment-aware behavior
crates/shuck-indexer - Semantic facts · Builds bindings, scopes, references, control flow, call graph, dataflow, and runtime facts
crates/shuck-semantic - Linter · Applies rule sets, suppressions, and emits violations across correctness, style, performance, portability, and security
crates/shuck-linter - Formatter · Formats shell scripts with its own context, simplification, streaming, and comment handling pipeline
crates/shuck-formatter - Diagnostics · Turns violations and spans into code frames, one-line output, and exit codes
crates/shuck/src/commands/check_output.rs
Quality gates
Tests, fuzzing, benchmarks, and corpus validation
- Fuzzing · Parser, lexer, arithmetic, formatter, and linter no-panic fuzz targets
fuzz - Benchmarks · Criterion-style benchmarks for lexer, parser, semantic, linter, formatter, and hot paths
crates/shuck-benchmark - Corpus tests · Large shell corpora, oracle fixtures, snapshots, and conformance metadata
crates/shuck-parser/tests/testdata/oils - Scripts · CI-adjacent scripts for corpus download, fuzz setup, benchmarking, profiling, and release automation
scripts
Docs and site
Rule docs generation and published website
- Specs · Architecture and behavior specs for parser, indexer, semantic model, linter, suppressions, formatter, run flow, and zsh support
specs - Rule docs · YAML rule references consumed by documentation and validation tooling
docs/rules - Docs generator · Generates website rule content from rule metadata
website/scripts/generate-rules.ts - Website · Publishes rule reference content and project documentation
website
Connections 25
- shuck CLI → Discovery: find inputs · Selects files and stdin sources before analysis
- Discovery → Cache: cache probe · Checks whether a file can be skipped
- Discovery → Parser: read source · Feeds shell text into parsing
- Cache → Diagnostics: short-circuit · Avoids reprocessing unchanged files
- Parser → AST: build syntax · Produces shared syntax structures
- Parser → Indexes: source spans · Provides text positions for indexing
- AST → Semantic facts: syntax input · Semantic analysis consumes AST structures
- Indexes → Semantic facts: location data · Supports comments, regions, and precise spans
- Semantic facts → Linter: facts · Rules consume semantic models rather than raw syntax
- Indexes → Linter: suppression spans · Supports directives and precise diagnostics
- Linter → Diagnostics: violations · Converts rule findings into user-facing diagnostics
- AST → Formatter: format input · Formatter operates on parsed shell structures
- Indexes → Formatter: comments · Preserves and repositions comments and whitespace
- Formatter → Diagnostics: rewrites · Emits formatted text for stdout or files
- Linter → Scripts: validated by · Rules are exercised through corpus and automation scripts
- Parser → Fuzzing: fuzzed by · Parser and lexer are major fuzz targets
- Formatter → Fuzzing: fuzzed by · Formatter consistency and validity are fuzzed
- Linter → Corpus tests: fixtures · Rule families are validated by snapshots and corpora
- Parser → Corpus tests: conformance · Parser is checked against large external corpora
- shuck CLI → Specs: guided by · Runtime behavior is documented by architectural specs
- Linter → Rule docs: documents · Rule metadata is published as YAML reference docs
- Docs generator → Rule docs: reads · Generates site content from rule documents
- Website → Docs generator: builds from · Website includes generated rule content
- Scripts → Benchmarks: runs · Automation drives benchmark and profiling workflows
- Scripts → Website: publishes · Supports website deployment and release automation