Repository navigation
Check in rustfmt.toml and enforce formatting in CI - #190
Merged
Merged
Conversation
CONTRIBUTING.md and the pull request template both ask for `cargo fmt --all` before opening a PR, and the coding guidelines ask to "keep the tree `rustfmt`-clean" — but no rustfmt config was checked in anywhere, and the tree was not clean. On stable 1.94.1 the documented step rewrote 18 files (4473 insertions, 1202 deletions): rustfmt's stock `fn_call_width` and `chain_width` of 60 split the calls and method chains this codebase keeps on one line. Following the instructions therefore meant either shipping a whole-repo reformat or hand-matching the surrounding style and skipping the step, which is what happened while preparing #189. No configuration reproduces the tree exactly, because the tree was never rustfmt output. A coordinate-descent sweep over every stable width knob (`max_width`, the six `use_small_heuristics` sub-widths, `fn_params_layout`, `style_edition`) bottoms out around 5700 residual diff lines, and the best-fitting combination is a curve fit to inconsistent hand formatting rather than a style anyone chose. 403 checked-in lines exceed 100 columns, among them breakable code such as `resolve_did` in `calls.rs` at 103 — a signature rustfmt would never emit at `max_width = 100`. So this checks in the two settings that are defensible on their own: the 100-column budget the code is visibly written to (the line-length histogram falls off a cliff there), and the widened heuristics that keep chains intact, which is the difference the report of this problem identified. Being unable to recover a config does not leave the repo stuck: one reviewed reformat ends drift that otherwise recurs for every contributor. The residual reformat those settings still want is applied here and nothing else, so it is reviewable on its own — 25 files, 1661 insertions, 1482 deletions, against 4473/1202 with no config at all. Purely whitespace and line breaks plus rustfmt's import ordering; `cargo build`, `cargo test` (270 tests) and the 11 pre-existing clippy warnings are unchanged. After it, `cargo fmt --all -- --check` is clean and idempotent on a fresh clone. If maintainers format with a toolchain or editor setting that is not in the repo, that config should be preferred over this one — it can be swapped in and the reformat redone against it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FefdMpLRBQ7cLihuQsi3Mf
CI ran build, test, the PocketIC e2e suite and the internal-identifier scan, but nothing checked formatting — so the rustfmt-clean tree CONTRIBUTING.md asks for was a request with no enforcement behind it, and it had already stopped being true. Checking in `rustfmt.toml` fixes the tree once; this is what keeps it fixed, because without it the drift just recurs and the next contributor to run the documented `cargo fmt --all` inherits someone else's reformat. A separate `fmt` job rather than a step in `test`: the two failures are independent and each should stay readable when the other fires, and since the job compiles nothing it runs in seconds in parallel, adding no wall-clock. `--check` only reports, never rewrites, and the local reproduction is the `cargo fmt --all` already documented. No new third-party action: this reuses `actions/checkout` at the same pinned SHA as the other jobs, and takes rustfmt from the runner's rustup like they take cargo. The toolchain is rolling `stable`, matching the sibling jobs, which does mean a stable release that changes rustfmt's output can turn this red with no code change — the comment records that the fix then is to re-run `cargo fmt --all`, not to pin. Verified against this branch: the check passes on the formatted tree, and fails as intended when deliberate drift is introduced. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FefdMpLRBQ7cLihuQsi3Mf
There was a problem hiding this comment.
🟢 Approval recommended
The only unresolved comment is a non-blocking grammar nit.
Pull request overview
Adds workspace-wide rustfmt configuration, reformats Rust sources, and enforces formatting in CI.
Changes:
- Adds
rustfmt.tomlwith a 100-column width and maximum small-item heuristics. - Applies formatting across the workspace.
- Adds a dedicated CI formatting check.
File summaries
| File | Description |
|---|---|
tests/routers.rs |
Applies formatting. |
src/metrics.rs |
Applies formatting. |
src/main.rs |
Applies formatting. |
src/lib.rs |
Applies formatting and import ordering. |
src/e2e_handshake.rs |
Applies formatting. |
rustfmt.toml |
Defines workspace formatting rules. |
crates/imcp2-local/src/setup.rs |
Applies formatting. |
crates/imcp2-local/src/server.rs |
Applies formatting. |
crates/imcp2-local/src/main.rs |
Applies formatting. |
crates/imcp2-local/src/login/tests.rs |
Applies formatting. |
crates/imcp2-local/src/login/slot.rs |
Applies formatting. |
crates/imcp2-local/src/login/routes.rs |
Applies formatting. |
crates/imcp2-local/src/login/mod.rs |
Applies formatting. |
crates/imcp2-local/src/e2e_local_login.rs |
Applies formatting. |
crates/imcp2-core/src/tools.rs |
Applies formatting and import ordering. |
crates/imcp2-core/src/skills.rs |
Applies formatting. |
crates/imcp2-core/src/management.rs |
Applies formatting. |
crates/imcp2-core/src/lib.rs |
Applies import/export ordering. |
crates/imcp2-core/src/iiconnect.rs |
Applies formatting. |
crates/imcp2-core/src/identities.rs |
Applies formatting. |
crates/imcp2-core/src/e2e_canister_tools.rs |
Applies formatting. |
crates/imcp2-core/src/discoverability.rs |
Applies formatting. |
crates/imcp2-core/src/discover.rs |
Applies formatting. |
crates/imcp2-core/src/compliance.rs |
Applies formatting. |
crates/imcp2-core/src/calls.rs |
Applies formatting and import ordering. |
.github/workflows/ci.yml |
Adds the formatting job; minor grammar nit: use “a rustfmt-clean” instead of “an rustfmt-clean.” |
Review details
- Files reviewed: 27/27 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Review nit: "an rustfmt-clean tree" should be "a rustfmt-clean tree" — `rustfmt` starts with a consonant sound, so "an" is wrong. Comment text only; the job itself is unchanged. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FefdMpLRBQ7cLihuQsi3Mf
sea-snake
approved these changes
Sep 3, 2026
9 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CONTRIBUTING.mdand this template both ask forcargo fmt --allbefore opening a PR, and the coding guidelines ask contributors to "keep the treerustfmt-clean" — but norustfmt.tomlwas checked in anywhere, and the tree was not clean. On stable 1.94.1 the documented step rewrote 18 files (4473 insertions, 1202 deletions), because rustfmt's stockfn_call_width/chain_widthof 60 split the calls and method chains this codebase keeps on one line.Following the instructions therefore meant either shipping a whole-repo reformat or hand-matching the surrounding style and skipping the step — which is what happened while preparing #189, where
cargo fmthad to be reverted and the added lines matched by hand.This checks in a config, applies the residual reformat it wants as its own commit, and adds a CI check so the drift cannot recur.
Important
The original config could not be recovered, because the tree was never rustfmt output. Please read "Why this config" below before reviewing the reformat — if you format with a toolchain or editor setting that is not in the repo, that config should be preferred over this one and the reformat redone against it.
Related issues
Follow-up to the formatting problem found while preparing #189.
Why this config
A coordinate-descent sweep over every stable rustfmt width knob —
max_width, all sixuse_small_heuristicssub-widths,fn_params_layout,style_edition, ~0.4 s per trial, run to convergence — cannot make the tree clean:max_width = 100(= the default)max_width = 100+use_small_heuristics = "Max"(this PR)max_widthpinned to 100max_widthfreemax_width = 120)It bottoms out around 5700 because the tree is hand-formatted to an approximate 100-column target, not machine-formatted. The decisive evidence: 403 checked-in lines exceed 100 columns, and some are ordinary breakable code, e.g.
crates/imcp2-core/src/calls.rs:383at 103 columns —rustfmt would never emit that at
max_width = 100, and atmax_width = 120it joins hundreds of correctly-split lines elsewhere. So no config reproduces the tree, and the best-fitting one (fn_call_width = 95,chain_width = 75,struct_lit_width = 40,array_width = 90,single_line_if_else_max_width = 80) is a curve fit to inconsistent hand formatting rather than a style anyone chose — five magic numbers to buy 9 % less churn.So the two settings here are the ones defensible on their own:
max_width = 100— the budget the code is visibly written to; the line-length histogram falls off a cliff there (835 lines at 90–99, then 296, 73, 36 …).use_small_heuristics = "Max"— the widened call/chain widths, which is exactly the difference identified in the report. The example line survives intact:src/metrics.rs:203is stillself.requests.with_label_values(&[route, method, &status]).inc();.Being unable to recover the original config does not leave the repo stuck: one reviewed reformat ends drift that otherwise recurs for every contributor.
Changes
Two commits, deliberately separate so the reformat is reviewable on its own:
rustfmt.toml+ residual reformat (25 files, 1661 insertions, 1482 deletions — against 4473/1202 with no config). Whitespace, line breaks and rustfmt's import ordering only; no behavioral change of any kind. The file carries comments explaining both settings and why they are one decision.fmtjob in.github/workflows/ci.ymlrunningcargo fmt --all -- --check. Its own job rather than a step intest, so a formatting nit does not hide the test results or vice versa; it compiles nothing, so it finishes in seconds in parallel and adds no wall-clock. No new third-party action — it reusesactions/checkoutat the same pinned SHA as the other jobs and takes rustfmt from the runner's rustup, as they take cargo.One tradeoff recorded in the workflow comment: the job tracks rolling
stable, matching the sibling jobs, so a stable release that changes rustfmt's output can turn it red with no code change. The fix then is to re-runcargo fmt --alland commit, not to pin.Testing
cargo build --locked --all-targetscargo test --locked --all-targets— 270 tests pass, identical tomaincargo fmt --all/cargo clippy --all-targets— 11 clippy warnings, byte-identical count before and after the reformat, so all pre-existing and untouched by this PRnpm test --prefix monitoring/mcp-status— not run; the dashboard is unchangedVerifying the stated goal on a fresh clone of this branch:
Also checked: formatting is idempotent (a second
cargo fmt --allis a no-op), and the new CI job genuinely fails when deliberate drift is introduced — it was not just passing vacuously.Checklist
CONTRIBUTING.md's commands now work as written, so its text is correct without edits, and its "keep the treerustfmt-clean" guideline becomes true and enforced rather than aspirational.🤖 Generated with Claude Code
https://claude.ai/code/session_01FefdMpLRBQ7cLihuQsi3Mf
Generated by Claude Code