Skip to content

Feat/add rustfmt clippy ci - #838

Open
AndyGauge wants to merge 1 commit into
rust-lang-nursery:masterfrom
AndyGauge:feat/add-rustfmt-clippy-ci
Open

Feat/add rustfmt clippy ci#838
AndyGauge wants to merge 1 commit into
rust-lang-nursery:masterfrom
AndyGauge:feat/add-rustfmt-clippy-ci

Conversation

@AndyGauge

@AndyGauge AndyGauge commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

fixes #837

Runs rustfmt and clippy in CI so the project's formatting expectations are
enforced automatically, instead of maintainers pointing them out by hand in
review (as in #836).

What runs in CI

A new CI workflow with a single lint job:

- cargo fmt --all -- --check
- cargo clippy --workspace --all-targets -- -D warnings
- cargo xtask fmt-md --check

Tests, spellcheck, and link checking stay where they already live
(mdbook-test.yml, spellcheck.yml, check-links.yml) rather than being
duplicated here.

Formatting the inline markdown examples

The skeptic-tested examples are written directly inside src/**/*.md, so
cargo fmt never sees them. cargo xtask fmt-md (new,
xtask/src/fmt_md.rs) extracts each fenced block, runs rustfmt at the
edition named by the fence, and writes the result back — preserving the
file's existing line endings, since part of the book is checked in as CRLF.
--check reports instead of rewriting.

Of 283 blocks scanned, 126 were reformatted and 66 skipped:

Skipped Why
47 {{#include}} of a workspace crate — already covered by cargo fmt --all
14 ignore blocks — not compiled by skeptic, need not be valid Rust
5 contain skeptic # hidden lines

The hidden-line blocks are left for a human on purpose. rustfmt reflows long
lines, so a hidden line that gets split would keep its # marker on only one
fragment — silently unhiding code in the published book. fmt-md reports them
by name rather than guessing.

Formatting the workspace shifted line numbers that three {{#include ...rs::N}}
anchors depend on, so those were recomputed (actor_pattern 168→163, reload
54→57, exif 23→29) and the rendered HTML checked to confirm each block still
ends at main's closing brace.

Clippy findings

Fixed rather than suppressed:

  • crates/web/src/links.rs — drop a no-op .into_iter()
  • crates/web/src/broken.rsIterator::next over .nth(0)
  • xtask/src/tests.rsio::Error::other in place of io::Error::new(ErrorKind::Other, _)
  • heapless_alloc.rs3.14 was an arbitrary sensor reading, not π, so it now
    uses a value that reads as a real measurement

Two are allowed per-crate, where the flagged code is the example:

  • manual_map in no_panic — the doc comment teaches exhaustively handling
    every path, which is what the spelled-out match shows
  • result_large_err in figmentfigment::Error is 208 bytes by upstream
    design, and boxing it would only obscure the example's error handling

Also

Makefile gains fmt, fmt-check, and lint targets; CLAUDE.md documents
cargo xtask fmt-md.

…own code

Adds a CI lint job running `cargo fmt --all --check`, `cargo clippy
--workspace --all-targets -D warnings`, and a new `cargo xtask fmt-md
--check` for the code blocks written inline in the book's markdown.
Tests, spellcheck, and link checking stay in their existing workflows.

The skeptic-tested examples live inside `src/**/*.md`, so `cargo fmt`
never sees them. `xtask/src/fmt_md.rs` extracts each block, runs rustfmt
at the edition named by the fence, and rewrites the markdown, preserving
the file's existing line endings. It skips `{{#include}}` blocks (already
covered by `cargo fmt --all`), `ignore` blocks, and blocks using skeptic
`# ` hidden lines -- rustfmt reflows long lines, which would move code
across the hidden/visible boundary and silently change what readers see.

Formatting the workspace shifted line numbers that three `{{#include}}`
anchors depend on, so those were recomputed.

Clippy findings fixed rather than suppressed:

  - web: drop a no-op `.into_iter()` and use `.next()` over `.nth(0)`
  - xtask: `io::Error::other` in place of `io::Error::new(Other, _)`
  - heapless_alloc: `3.14` was an arbitrary sensor reading, not PI, so
    use a value that reads as a real measurement

Two lints are allowed per-crate where the example is the point:
`manual_map` in no_panic (the doc comment teaches exhaustive matching)
and `result_large_err` in figment (`figment::Error` is 208 bytes by
upstream design).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@AndyGauge
AndyGauge force-pushed the feat/add-rustfmt-clippy-ci branch from 221da33 to 3b6d5ce Compare August 24, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI step for rustfmt

1 participant