repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

clippy and cargo research

909e06b38cb904657af73b3ec3c096e44e67d046

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (2)

+57 / −4 text lines

Diff layout

.config/clippy.toml

Modified

+0 / −4 text lines

66# Lint enablement/disablement belongs in .cargo/config.toml rustflags.
77# See .cargo/config.toml for the full rustflags list.
9# -----------------------------------------------------------------------------
10# Cognitive Complexity Threshold
11# -----------------------------------------------------------------------------
129# TUI event routing naturally hits this. Review functions >20 during review.
1310cognitive-complexity-threshold = 25
1512# No MSRV pin: project tracks latest stable Rust.
16# Without msrv, clippy suggests idioms up to the current toolchain — desired.

.system/research/SMH-RESEARCH-JTJLLCMH-cargo-and-clippy-lint-scoping/index.md

Added
new file mode 100644

+57 / −0 text lines

1---
2id: SMH-RESEARCH-JTJLLCMH
3type: research
4title: "Cargo and Clippy Lint Scoping"
5---
6
7# Cargo and Clippy Lint Scoping
8
9Idiomatic ways to scope lint levels by target (production, tests, guests), verified against current docs and this repository.
11## Mechanisms, verified
13| mechanism | scope unit | idiomatic for | verified |
14|---|---|---|---|
15| `[workspace.lints]` + `[lints] workspace = true` | package (all its targets) | stable levels owned in Cargo.toml; cargo-native since 1.74 | [cargo workspaces](https://doc.rust-lang.org/cargo/reference/workspaces.html) |
16| `[lints.clippy]` per package | package | per-crate exceptions without attrs | [clippy configuration](https://doc.rust-lang.org/clippy/configuration.html) |
17| attributes `#[deny]` / `#[expect]` | item, module, file | visible, reasoned, local exceptions | clippy docs |
18| rustc args after `--` (`-A clippy::x`) | invocation | phase splits (`--tests`, `--lib`) and one-shot overrides; last level wins over earlier flags | rustc lint levels |
19| `.cargo/config.toml` rustflags | every rustc invocation | workspace-wide zero-warning policy incl. builds | current smith setup |
20| `clippy.toml` / `.clippy.toml` | whole run | VALUES only (thresholds), never levels | clippy docs |
22Nightly-only: `cargo`'s own lint group (`unused_dependencies` etc.) — not usable on stable.
24## Facts discovered in this repository
26- `CLIPPY_CONF_DIR` is real and documented: priority CLIPPY_CONF_DIR → CARGO_MANIFEST_DIR → cwd, then parent walk.
27- Empirically: without the env var, `clippy.toml` under `.config/` is NOT discovered — raw `cargo clippy` and rust-analyzer silently lose threshold configuration. With the env var (xtask gate), it parses.
28- Clippy levels cannot be scoped by target type (`--tests`) through any cargo-native table; that gap is what invocation splitting covers.
29- `#[expect]` beats `-A` from the command line: an expected-but-allowed lint becomes an unfulfilled expectation error, so attrs and phase allowances do not compose silently.
31## Idiomatic shape for smith
33```text
34policy levels .cargo/config.toml rustflags (unchanged) — the
35 zero-warning law applies to every compilation
36thresholds .config/clippy.toml + CLIPPY_CONF_DIR in xtask
37per-crate levels [lints] tables when a crate needs a standing
38 exception (none today)
39local exceptions #[expect(..., reason)] attributes (status quo)
40target phases xtask clippy split: --lib/--bins strict,
41 --tests with assertion allowances, guests with
42 pedantic+missing_docs allowances
43```
45Phase allowances after `--` are idiomatic for CI orchestration; they live in one auditable place and cannot leak into source.
47## Unresolved questions
49- Raw-run configuration loss: developers and rust-analyzer invoke clippy without CLIPPY_CONF_DIR and get default thresholds. Options: symlink `.clippy.toml` at root into `.config/` (root file, law tension), law exception for clippy discovery, or accept gate-only configuration and document it.
50- Precedence between `[lints]` table levels and config rustflags is undocumented; if both are adopted, test empirically before mixing.
51- Whether test allowances should eventually move into a `[lints]`-based scheme if cargo grows per-target lint tables.
53## Sources
55- Cargo lints inheritance — <https://doc.rust-lang.org/cargo/reference/workspaces.html>
56- Clippy configuration discovery — <https://doc.rust-lang.org/clippy/configuration.html>
57- Cargo's own (nightly) lint groups — <https://doc.rust-lang.org/cargo/reference/lints.html>