rust_clippy_test.bzl

rust_clippy_test

load("@rules_rust//rust:rust_clippy_test.bzl", "rust_clippy_test")

rust_clippy_test(name, platform, targets, transitive)

A test rule that runs clippy over a set of Rust targets.

By default (transitive = False), only the exact targets listed are checked. Set transitive = True to walk deps, proc_macro_deps, and crate so that listing a top-level target checks its whole crate graph.

The clippy actions run during the build phase, so a clippy failure fails bazel test before the test executable is invoked. The rule also exposes the collected markers under the clippy_checks output group, so bazel build //x:my_clippy_test --output_groups=clippy_checks drives the clippy actions without running the test.

When capture_clippy_output or clippy_output_diagnostics is set globally clippy exits 0 even on real issues; in that case the runner inspects the captured stderr / JSON diagnostics and reports the verdict.

An optional platform attribute transitions targets to the given platform before running clippy.

Example:

load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_clippy_test", "rust_library")

rust_library(
    name = "lib",
    srcs = ["src/lib.rs"],
    edition = "2021",
)

rust_binary(
    name = "app",
    srcs = ["src/main.rs"],
    edition = "2021",
    deps = [":lib"],
)

rust_clippy_test(
    name = "clippy_app_only_test",
    targets = [":app"],
)

rust_clippy_test(
    name = "clippy_tree_test",
    targets = [":app"],
    transitive = True,
)

Targets tagged no_clippy, no_lint, nolint, or noclippy are skipped.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
platformOptional platform to transition targets to before running the aspect. When set, --platforms is switched to this label for the duration of this rule's aspect actions.LabeloptionalNone
targetsRust targets to run clippy on.List of labelsoptional[]
transitiveIf True, lint targets and every crate reachable via deps, proc_macro_deps, and crate. If False, lint only the exact targets listed.BooleanoptionalFalse