|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Instructions for AI coding agents working on `torrust-linting`. |
| 4 | + |
| 5 | +## Project overview |
| 6 | + |
| 7 | +`torrust-linting` is a Rust library and CLI binary that runs all standard Torrust project linters in one command. It wraps external tools (markdownlint, yamllint, taplo, cspell, shellcheck) and Rust built-ins (clippy, rustfmt) behind a unified interface. |
| 8 | + |
| 9 | +- **Crate type**: hybrid — library (`torrust_linting`) + binary (`linter`) |
| 10 | +- **Rust edition**: 2021, `rust-version = "1.85"` |
| 11 | +- **License**: MIT |
| 12 | + |
| 13 | +## Build commands |
| 14 | + |
| 15 | +```sh |
| 16 | +cargo build # Build library + binary |
| 17 | +cargo build --bin linter # Build only the CLI binary |
| 18 | +cargo build --release # Release build |
| 19 | +``` |
| 20 | + |
| 21 | +## Run the linter |
| 22 | + |
| 23 | +```sh |
| 24 | +cargo run # Run all linters (default) |
| 25 | +cargo run -- all # Explicit "all" |
| 26 | +cargo run -- markdown # Single linter |
| 27 | +cargo run -- yaml |
| 28 | +cargo run -- toml |
| 29 | +cargo run -- cspell |
| 30 | +cargo run -- clippy |
| 31 | +cargo run -- rustfmt |
| 32 | +cargo run -- shellcheck |
| 33 | +``` |
| 34 | + |
| 35 | +After a build you can also run the binary directly: |
| 36 | + |
| 37 | +```sh |
| 38 | +./target/debug/linter all |
| 39 | +``` |
| 40 | + |
| 41 | +## Testing |
| 42 | + |
| 43 | +There are no unit tests at the moment. The primary verification is running the linter against itself: |
| 44 | + |
| 45 | +```sh |
| 46 | +cargo run # Must exit 0 — this is the CI gate |
| 47 | +``` |
| 48 | + |
| 49 | +**This is mandatory before every commit.** The CI workflow (`.github/workflows/linting.yml`) runs the exact same command and will reject any PR that does not pass. Do not open a PR without confirming exit code 0 locally first. |
| 50 | + |
| 51 | +## Code style |
| 52 | + |
| 53 | +- Format with `cargo fmt` before committing. The project uses a custom `rustfmt.toml` (`group_imports = "StdExternalCrate"`, `max_width = 130`). |
| 54 | +- No clippy warnings allowed (`cargo clippy -- -D warnings`). |
| 55 | +- TOML files must pass `taplo fmt --check **/*.toml`. Auto-fix with `taplo fmt **/*.toml`. |
| 56 | +- Markdown files must pass `markdownlint`. |
| 57 | +- YAML files must pass `yamllint -c .yamllint-ci.yml`. |
| 58 | +- Spell-check all files with `cspell`. Add new technical terms to `project-words.txt` (one word per line, alphabetical order). |
| 59 | + |
| 60 | +## Adding a new linter |
| 61 | + |
| 62 | +1. Create `src/linters/<name>.rs` with a public `run_<name>_linter() -> Result<()>` function. |
| 63 | +2. Register it in `src/linters/mod.rs` (`pub mod <name>; pub use <name>::run_<name>_linter;`). |
| 64 | +3. Re-export from `src/lib.rs`. |
| 65 | +4. Add a `Commands` variant in `src/cli.rs` and handle it in `execute_command()`. |
| 66 | +5. Add the call to `run_all_linters()` in `src/cli.rs`. |
| 67 | + |
| 68 | +## Configuration files |
| 69 | + |
| 70 | +Place these in the project root when using this linter on another repo: |
| 71 | + |
| 72 | +| File | Used by | |
| 73 | +| -------------------- | ------------ | |
| 74 | +| `.markdownlint.json` | markdownlint | |
| 75 | +| `.yamllint-ci.yml` | yamllint | |
| 76 | +| `.taplo.toml` | taplo | |
| 77 | +| `cspell.json` | cspell | |
| 78 | + |
| 79 | +## PR instructions |
| 80 | + |
| 81 | +- **Run `cargo run` and confirm exit code 0 before every commit and before opening a PR. PRs that fail the linting CI will be rejected.** |
| 82 | +- Branch naming: `feat/<short-description>`, `fix/<short-description>`, `chore/<short-description>`. |
| 83 | +- Commit messages follow [Conventional Commits](https://www.conventionalcommits.org/): `feat:`, `fix:`, `chore:`, `docs:`, `refactor:`. |
| 84 | +- Keep `Cargo.lock` committed (the crate ships a binary). |
0 commit comments