Skip to content

fix(lints): remediate workspace Clippy violations and enforce cognitive complexity #2134

Closed

Description

@josecelano

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_event is 59/25.
  • packages/swarm-coordination-registry/src/statistics/event/listener.rs: dispatch_events is 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 = true to 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 all CI 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-linting repository 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_event and dispatch_events meet the default cognitive-complexity threshold.
  • Root Cargo.toml denies clippy::cognitive_complexity.
  • cargo clippy --workspace --all-targets --all-features exits successfully without extra lint flags.
  • linter all exits 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 --check
  • cargo clippy --workspace --all-targets --all-features
  • linter all
  • cargo test -p torrust-tracker-swarm-coordination-registry
  • cargo test --doc --workspace
  • cargo 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

  1. added theissue type on Sep 3, 2026
  2. self-assigned this
    on Sep 3, 2026
  3. changed the issue type fromtoon Sep 3, 2026
  4. added a commit that references this issue on Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions