Skip to content

Run clippy on every Bazel build via the rules_rust aspect - #461

Draft
tinder-maxwellelliott wants to merge 1 commit into
masterfrom
claude/clippy-rules-rust-aspect-976109
Draft

Run clippy on every Bazel build via the rules_rust aspect#461
tinder-maxwellelliott wants to merge 1 commit into
masterfrom
claude/clippy-rules-rust-aspect-976109

Conversation

@tinder-maxwellelliott

Copy link
Copy Markdown
Collaborator

What changed

  • .bazelrc now applies @rules_rust//rust:defs.bzl%rust_clippy_aspect (plus the clippy_checks output group) on the build command, so every bazel build/test/run/coverage invocation lints first-party Rust crates immediately.
  • Fixed the one lint the aspect surfaced on its first run: a needless_borrow in tools/coverage/src/enforce.rs.

Why

Clippy previously only ran as a cargo clippy --all-targets -- -D warnings step in CI, so lint issues weren't caught during local Bazel development — and crates outside the Cargo workspace were never linted at all. The enforce.rs fix in this PR is a live example: tools/coverage is Bazel-only, so the cargo pass never saw it.

The aspect matches the existing CI bar: it denies warnings by default (-Dwarnings), only attaches to rules_rust targets via required_providers, and skips external crate_universe crates. A target can opt out with tags = ["no-clippy"]. CI's Bazel jobs pick this up automatically through .bazelrc, so no workflow changes are needed. The cargo clippy CI step stays, since it covers things Bazel doesn't build (tests/e2e, build.rs via cargo).

Verification

  • bazel build //src:all //tools/coverage:all passes with .clippy.ok markers produced for all seven first-party crates (libs, bins, and test targets).
  • A seeded clone_on_copy warning fails the build immediately (then reverted).
  • Non-Rust targets (//:license), bazel run --script_path //:bazel-diff-rust, and cquery — the paths bazel-diff-example.sh exercises — are unaffected.
  • The aspect loads and analyzes cleanly under Bazel 7.x and 9.x (build --nobuild); everything else ran on the pinned 8.5.1. MODULE.bazel.lock stays clean under the pinned version.
  • //tools/coverage:lcov_merger_test passes after the lint fix.

🤖 Generated with Claude Code

Wire rust_clippy_aspect and the clippy_checks output group into .bazelrc's
build command so first-party Rust crates are linted immediately on any
bazel build/test/run/coverage invocation, instead of waiting for the
cargo clippy pass in CI. The aspect only attaches to rules_rust targets,
skips external crates, and denies warnings by default — the same bar as
the existing cargo clippy -D warnings CI gate.

Fix the needless_borrow lint in tools/coverage/src/enforce.rs that the
aspect caught on its first run: tools/coverage is outside the Cargo
workspace, so the cargo clippy CI pass never saw it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant