|
| 1 | +# Clippy Support |
| 2 | + |
| 3 | +This project includes built-in support for running [Clippy](https://github.com/rust-lang/rust-clippy), the Rust linter, on all Rust WASM components. |
| 4 | + |
| 5 | +## Running Clippy |
| 6 | + |
| 7 | +### On All Targets |
| 8 | + |
| 9 | +To run clippy on all Rust targets in the project: |
| 10 | + |
| 11 | +```bash |
| 12 | +bazel build --config=clippy //... |
| 13 | +``` |
| 14 | + |
| 15 | +Or use the provided script: |
| 16 | + |
| 17 | +```bash |
| 18 | +./scripts/clippy.sh |
| 19 | +``` |
| 20 | + |
| 21 | +### On Specific Targets |
| 22 | + |
| 23 | +To run clippy on a specific target, you can use the `rust_wasm_component_clippy` rule: |
| 24 | + |
| 25 | +```starlark |
| 26 | +load("@rules_wasm_component//rust:defs.bzl", "rust_wasm_component", "rust_wasm_component_clippy") |
| 27 | + |
| 28 | +rust_wasm_component( |
| 29 | + name = "my_component", |
| 30 | + srcs = ["src/lib.rs"], |
| 31 | + # ... |
| 32 | +) |
| 33 | + |
| 34 | +rust_wasm_component_clippy( |
| 35 | + name = "my_component_clippy", |
| 36 | + target = ":my_component", |
| 37 | +) |
| 38 | +``` |
| 39 | + |
| 40 | +Then run: |
| 41 | + |
| 42 | +```bash |
| 43 | +bazel test //path/to:my_component_clippy |
| 44 | +``` |
| 45 | + |
| 46 | +## Configuration |
| 47 | + |
| 48 | +### Default Lints |
| 49 | + |
| 50 | +By default, clippy is configured with the following lints as errors: |
| 51 | +- `warnings` - All compiler warnings |
| 52 | +- `clippy::all` - All default clippy lints |
| 53 | +- `clippy::correctness` - Code that is likely incorrect or useless |
| 54 | +- `clippy::style` - Code that should be written in a more idiomatic way |
| 55 | +- `clippy::complexity` - Code that does something simple but in a complex way |
| 56 | +- `clippy::perf` - Code that can be written more efficiently |
| 57 | + |
| 58 | +### Custom Configuration |
| 59 | + |
| 60 | +You can customize clippy behavior by modifying `.bazelrc`: |
| 61 | + |
| 62 | +```bash |
| 63 | +# Add custom clippy flags |
| 64 | +build:clippy --@rules_rust//:clippy_flags=-D,warnings,-W,clippy::pedantic |
| 65 | +``` |
| 66 | + |
| 67 | +### Per-Target Configuration |
| 68 | + |
| 69 | +You can also configure clippy on a per-target basis: |
| 70 | + |
| 71 | +```starlark |
| 72 | +rust_wasm_component_clippy( |
| 73 | + name = "my_component_clippy", |
| 74 | + target = ":my_component", |
| 75 | + tags = ["manual"], # Don't run with //... |
| 76 | +) |
| 77 | +``` |
| 78 | + |
| 79 | +## CI Integration |
| 80 | + |
| 81 | +Clippy is automatically run in CI for all pull requests. To ensure your code passes CI: |
| 82 | + |
| 83 | +1. Run clippy locally before pushing: `bazel build --config=clippy //...` |
| 84 | +2. Fix any issues reported by clippy |
| 85 | +3. Commit your changes |
| 86 | + |
| 87 | +## Suppressing Lints |
| 88 | + |
| 89 | +If you need to suppress a specific lint: |
| 90 | + |
| 91 | +```rust |
| 92 | +// Suppress for entire file |
| 93 | +#![allow(clippy::specific_lint)] |
| 94 | + |
| 95 | +// Suppress for specific code block |
| 96 | +#[allow(clippy::specific_lint)] |
| 97 | +fn my_function() { |
| 98 | + // ... |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +However, please use suppressions sparingly and document why they're necessary. |
0 commit comments