|
| 1 | +# init4 custom lints |
| 2 | + |
| 3 | +Custom [dylint](https://github.com/trailofbits/dylint) lints for init4 Rust projects. |
| 4 | + |
| 5 | +## Lints |
| 6 | + |
| 7 | +### `bare_instrument_fields` |
| 8 | + |
| 9 | +Detects bare identifiers in `#[instrument(fields(x))]` that silently create |
| 10 | +`tracing::field::Empty` span fields instead of capturing the variable value. |
| 11 | + |
| 12 | +Three cases are flagged: |
| 13 | + |
| 14 | +- **Bare param with `skip_all`** - `fields(x)` creates an Empty field instead of |
| 15 | + capturing the parameter. Suggests replacing `skip_all` with a concrete `skip(...)`. |
| 16 | +- **Bare param without `skip_all`** - `fields(x)` shadows the auto-captured |
| 17 | + parameter with an Empty value. Suggests removing from `fields()`. |
| 18 | +- **Bare non-param, never recorded** - `fields(x)` where `x` is not a parameter |
| 19 | + and no `.record("x", ...)` call exists in the body. The field is permanently Empty. |
| 20 | + |
| 21 | +Fields that are assigned (`x = expr`), format-hinted (`%x`, `?x`), or recorded |
| 22 | +via `.record("x", ...)` in the function body are not flagged. |
| 23 | + |
| 24 | +## Integrating into a repo |
| 25 | + |
| 26 | +### 1. Add workspace metadata |
| 27 | + |
| 28 | +In the consumer repo's `Cargo.toml`: |
| 29 | + |
| 30 | +```toml |
| 31 | +[workspace.metadata.dylint] |
| 32 | +libraries = [ |
| 33 | + { git = "https://github.com/init4tech/lints", pattern = "instrument-fields" } |
| 34 | +] |
| 35 | +``` |
| 36 | + |
| 37 | +### 2. Add the CI workflow |
| 38 | + |
| 39 | +In `.github/workflows/dylint.yml`: |
| 40 | + |
| 41 | +```yaml |
| 42 | +name: dylint |
| 43 | + |
| 44 | +on: |
| 45 | + push: |
| 46 | + branches: [main] |
| 47 | + pull_request: |
| 48 | + |
| 49 | +jobs: |
| 50 | + dylint: |
| 51 | + uses: init4tech/lints/.github/workflows/dylint.yml@main |
| 52 | +``` |
| 53 | +
|
| 54 | +To check specific packages only: |
| 55 | +
|
| 56 | +```yaml |
| 57 | +jobs: |
| 58 | + dylint: |
| 59 | + uses: init4tech/lints/.github/workflows/dylint.yml@main |
| 60 | + with: |
| 61 | + packages: "my-crate other-crate" |
| 62 | +``` |
| 63 | +
|
| 64 | +### Running locally |
| 65 | +
|
| 66 | +```sh |
| 67 | +rustup toolchain install nightly-2026-03-17 --component rustc-dev llvm-tools-preview |
| 68 | +cargo install cargo-dylint@5.0.0 dylint-link@5.0.0 |
| 69 | + |
| 70 | +# If using workspace metadata: |
| 71 | +cargo +nightly-2026-03-17 dylint --all --workspace |
| 72 | + |
| 73 | +# Or with a local checkout of the lints repo: |
| 74 | +DYLINT_LIBRARY_PATH=<PATH TO REPO>/instrument-fields/target/debug \ |
| 75 | + cargo +nightly-2026-03-17 dylint --all --no-deps --workspace |
| 76 | +``` |
| 77 | + |
| 78 | +## Development |
| 79 | + |
| 80 | +```sh |
| 81 | +cd instrument-fields |
| 82 | +cargo build # builds the lint .so |
| 83 | +cargo test # runs UI tests |
| 84 | +``` |
| 85 | + |
| 86 | +Pinned to `nightly-2026-03-17` for compatibility with `dylint_linting` 5.0.0. |
0 commit comments