chore: rust-idiomatic compliance pass across M3 + M2 modules#21
Open
brunota20 wants to merge 1 commit into
Open
chore: rust-idiomatic compliance pass across M3 + M2 modules#21brunota20 wants to merge 1 commit into
brunota20 wants to merge 1 commit into
Conversation
QA pass against the team's rust-idiomatic skill ahead of M4. All
mandatory rules now hold; the cleanup is mostly mechanical with a
handful of small typing improvements where the rule asked for one
thiserror enum per error type.
## Em-dash purge (rule: "no em-dashes anywhere")
Replaced every U+2014 with " - " across .rs / .toml / .md:
- 51 source-file occurrences
- 5 Cargo.toml comments
- 366 occurrences across docs/*.md (most in ADRs and the
deployment / tutorial / sdk landings)
Grep gate: `grep -rn '—' crates/ modules/ docs/` returns 0.
## `#![cfg_attr(not(test), warn(unused_crate_dependencies))]`
Added to every crate root that previously lacked it:
- crates/shepherd-sdk/src/lib.rs
- crates/shepherd-sdk-test/src/lib.rs
- modules/{example,twap-monitor,ethflow-watcher}/src/lib.rs
- modules/examples/{price-alert,balance-tracker}/src/lib.rs
`crates/nexum-engine/src/main.rs` already had it.
## Unused-dep cleanup driven by the lint
- shepherd-sdk dropped `serde` (only `serde_json` is actually
imported; cowprotocol re-exports carry their own serde derive
transitively).
- balance-tracker dropped its direct `alloy-primitives` dep —
now goes through `shepherd_sdk::prelude::{Address, U256,
address}`. Tests adapt.
## thiserror conversions (rule: "one flat thiserror enum per
## module/backend; no String-wrapping of upstream errors")
- `shepherd_sdk::host::HostError` gains `#[derive(thiserror::
Error)]` + `#[error("{domain}: {message} (code={code},
kind={kind:?})")]`. Was a plain struct without Display.
Added `thiserror = "2"` as a dep.
- `modules/twap-monitor::BuildError`: hand-rolled Display impl
replaced with `#[derive(thiserror::Error)]` + per-variant
`#[error(...)]` + `#[from] cowprotocol::Error`. The map_err
at the call site collapses to `?`.
- `modules/ethflow-watcher::BuildError`: same conversion (4
variants, one of them `#[from]`).
Both modules add `thiserror = "2"` as a direct dep.
## Verification
- `cargo clippy --all-targets --workspace -- -D warnings` clean.
- `cargo test --workspace`: 121 tests pass.
- nexum-engine 41, shepherd-sdk 27, shepherd-sdk-test 8 + 1
doctest, twap-monitor 13, ethflow-watcher 7, price-alert
11, balance-tracker 13.
## Architecture notes (no code changes)
- `#[non_exhaustive]` is *not* applied to public enums
(`HostErrorKind`, `LogLevel`, `RetryAction`, `PollOutcome`).
The first two mirror the WIT 0.2 enums (locked at the WIT
contract layer); the last two are intentional 3- and 5-arm
contracts with no expected growth. If a future kind shows
up, the rule applies then.
- `parse_config` / `parse_settings` in the example modules
return `Result<T, String>` rather than a typed enum. The
rule's "no string-wrapping" applies to error variants that
*wrap* an upstream `std::error::Error`; one-shot config
parsers with bespoke per-field messages are pragmatic. The
error surface is internal to the module's `init` and not
part of the orderbook retry contract.
3 tasks
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
QA pass against the team's `rust-idiomatic` skill ahead of M4 work. Mostly mechanical (em-dash purge, missing lint attribute) with a handful of small typing improvements where the rule asked for thiserror enums.
Stacked on top of the M3 PR chain (#20). When the stack squashes, this is the natural last commit.
Em-dash purge (`grep -rn '—'` now returns 0)
.rsfilesCargo.tomlcomments.mddocs (ADRs, tutorial, SDK + deployment landings)#![cfg_attr(not(test), warn(unused_crate_dependencies))]added to every crate rootcrates/shepherd-sdk,crates/shepherd-sdk-testmodules/{example,twap-monitor,ethflow-watcher}modules/examples/{price-alert,balance-tracker}Unused-dep cleanup driven by the lint
shepherd-sdkdroppedserde(onlyserde_jsonis imported directly; cowprotocol's serde derive rides through transitively).balance-trackerdropped its directalloy-primitivesdep — now goes viashepherd_sdk::prelude::{Address, U256, address}. Tests adapt.thiserror conversions
shepherd_sdk::host::HostError: was a plain struct; now#[derive(thiserror::Error)]with#[error(\"{domain}: {message} (code={code}, kind={kind:?})\")]. Addedthiserror = \"2\"to the crate.modules/twap-monitor::BuildError: hand-rolledimpl Displayreplaced with derive +#[from] cowprotocol::Error. Call site collapses to?.modules/ethflow-watcher::BuildError: same conversion (4 variants, one#[from]).Both modules pick up
thiserror = \"2\"as a direct dep.Verification
cargo clippy --all-targets --workspace -- -D warnings— clean.cargo test --workspace— 121 tests pass (nexum-engine 41, shepherd-sdk 27, shepherd-sdk-test 8 + 1 doctest, twap-monitor 13, ethflow-watcher 7, price-alert 11, balance-tracker 13).Architecture notes (deliberate non-changes)
#[non_exhaustive]is not applied to public enums.HostErrorKind/LogLevelmirror the WIT 0.2 enums (locked at the WIT contract layer);RetryAction/PollOutcomeare intentional 3- and 5-arm contracts with no expected growth. If a future kind shows up, the rule applies then.parse_config/parse_settingsin the example modules returnResult<T, String>rather than a typed enum. The rule's "no string-wrapping" applies to error variants that wrap an upstreamstd::error::Error; one-shot config parsers with bespoke per-field messages are pragmatic. The error surface is internal to the module'sinit.Linear: chore (not tied to a specific BLEU issue).