xref: /aosp_15_r20/external/bazelbuild-rules_rust/docs/rust_clippy.vm (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1*d4726bddSHONG Yifan#[[
2*d4726bddSHONG Yifan## Overview
3*d4726bddSHONG Yifan]]#
4*d4726bddSHONG Yifan
5*d4726bddSHONG Yifan[Clippy][clippy] is a tool for catching common mistakes in Rust code and improving it. An
6*d4726bddSHONG Yifanexpansive list of lints and the justification can be found in their [documentation][docs].
7*d4726bddSHONG Yifan
8*d4726bddSHONG Yifan[clippy]: https://github.com/rust-lang/rust-clippy#readme
9*d4726bddSHONG Yifan[docs]: https://rust-lang.github.io/rust-clippy/
10*d4726bddSHONG Yifan
11*d4726bddSHONG Yifan#[[
12*d4726bddSHONG Yifan### Setup
13*d4726bddSHONG Yifan]]#
14*d4726bddSHONG Yifan
15*d4726bddSHONG YifanSimply add the following to the `.bazelrc` file in the root of your workspace:
16*d4726bddSHONG Yifan
17*d4726bddSHONG Yifan```text
18*d4726bddSHONG Yifanbuild --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
19*d4726bddSHONG Yifanbuild --output_groups=+clippy_checks
20*d4726bddSHONG Yifan```
21*d4726bddSHONG Yifan
22*d4726bddSHONG YifanThis will enable clippy on all [Rust targets](./defs.md).
23*d4726bddSHONG Yifan
24*d4726bddSHONG YifanNote that targets tagged with `no-clippy` will not perform clippy checks
25*d4726bddSHONG Yifan
26*d4726bddSHONG YifanTo use a local clippy.toml, add the following flag to your `.bazelrc`. Note that due to
27*d4726bddSHONG Yifanthe upstream implementation of clippy, this file must be named either `.clippy.toml` or
28*d4726bddSHONG Yifan`clippy.toml`. Using a custom config file requires Rust 1.34.0 or newer.
29*d4726bddSHONG Yifan
30*d4726bddSHONG Yifan```text
31*d4726bddSHONG Yifanbuild --@rules_rust//:clippy.toml=//:clippy.toml
32*d4726bddSHONG Yifan```
33