Repository navigation
Description
Goal
Refactor all currently exposed workspace Clippy violations and make clippy::cognitive_complexity a tracked denied Cargo lint that the existing linter all CI run enforces across the workspace.
Background
The original explicit cognitive-complexity check fails with Rust 1.98.0 and Clippy 0.1.98:
packages/swarm-coordination-registry/src/statistics/event/handler.rs:handle_eventis 59/25.packages/swarm-coordination-registry/src/statistics/event/listener.rs:dispatch_eventsis 29/25.
Enabling [lints] workspace = true in every workspace package was tested locally. The flag-free command cargo clippy --workspace --all-targets --all-features then reported 87 diagnostics, chiefly clippy::use_self (32), clippy::missing_const_for_fn (26), and clippy::derive_partial_eq_without_eq (14), primarily in http-protocol and udp-protocol.
CI already runs linter all on stable and nightly, and that command runs workspace Clippy. No dedicated CI workflow step is required: once all packages inherit workspace lints and the lint is declared in Cargo.toml, CI enforces it.
Scope
- Add
[lints] workspace = trueto every workspace package manifest. - Fix every diagnostic exposed by the resulting workspace lint policy without weakening it through lint allowances.
- Refactor the two cognitive-complexity violations while preserving metrics, labels, listener cancellation priority, closed-receiver termination, lagged-receiver continuation, and logging behavior.
- Add
cognitive_complexity = { level = "deny", priority = -1 }to root[workspace.lints.clippy]only after the workspace is clean under the inherited existing policy. - Verify the existing
linter allCI step fails on a cognitive-complexity violation and passes after remediation. - Update lint-policy documentation as needed.
Out of Scope
- Changing Clippy's default cognitive-complexity threshold.
- Adding
#[allow(clippy::cognitive_complexity)]. - Changing the external
torrust-lintingrepository or adding a redundant direct Clippy CI step.
Acceptance Criteria
- All 26 workspace manifests inherit workspace lints.
- Every diagnostic exposed by full workspace-lint inheritance is fixed without policy-weakening lint allowances.
-
handle_eventanddispatch_eventsmeet the default cognitive-complexity threshold. - Root
Cargo.tomldeniesclippy::cognitive_complexity. -
cargo clippy --workspace --all-targets --all-featuresexits successfully without extra lint flags. -
linter allexits successfully. - Relevant focused tests, documentation tests, and full workspace tests pass.
- Manual listener behavior verification covers cancellation, closed receiver, successful delivery, and lagged receiver behavior.
Verification
cargo fmt --checkcargo clippy --workspace --all-targets --all-featureslinter allcargo test -p torrust-tracker-swarm-coordination-registrycargo test --doc --workspacecargo test --tests --benches --examples --workspace --all-targets --all-features- Pre-commit and pre-push hooks when applicable.
Full implementation specification: docs/issues/drafts/fix-cognitive-complexity-lint-enforcement.md.
Activity
docs(issues): add issue specification for torrust#2134
Merge #2135: docs(issues): add issue specification for #2134
docs(issues): record torrust#2134 implementation start
docs(issues): expand torrust#2134 cognitive complexity scope
docs(issues): expand torrust#2134 protocol core scope
docs(issues): expand torrust#2134 UDP server scope
docs(issues): expand torrust#2134 profiling scope
docs(issues): record torrust#2134 enforcement evidence
docs(issues): record torrust#2134 final validation
docs(issues): record torrust#2134 implementation retrospective
docs(issues): complete torrust#2134 task review
Merge torrust#2147: chore(lints): [torrust#2134] enforce cognitive co…