Skip to content

Commit ec2fd4e

Browse files
authored
chore: add pre-commit config for local Rust lint checks (#1871)
# What does this PR do? Adds a `.pre-commit-config.yaml` that mirrors CI lint checks for local development: - **pre-commit**: `cargo +nightly-2026-02-08 fmt --all` and `dd-rust-license-tool check` (only on Cargo.toml/lock and license input changes) - **pre-push**: `cargo clippy --workspace --all-targets --all-features -- -D warnings` # Motivation Since I started using coding agents, I find pre-commit hooks invaluable — they greatly reduce back-and-forths and CI costs. The more checks that run locally before code leaves my machine, the fewer wasted CI cycles and review round-trips. I'm not specifically promoting [pre-commit](https://pre-commit.com/) (the Python tool), but it's a nice framework that's trivial to install, especially with `uv`: ```bash uv tool install pre-commit ``` There are probably a million similar frameworks, but this is a nice example. # Additional Notes Completely opt-in. If you haven't configured the git hooks locally, none of these checks will fire. Install with: ```bash GIT_CONFIG_GLOBAL=/dev/null pre-commit install GIT_CONFIG_GLOBAL=/dev/null pre-commit install --hook-type pre-push ``` (`GIT_CONFIG_GLOBAL=/dev/null` works around the DD global `core.hooksPath` setting.) rustfmt is pinned to `nightly-2026-02-08` to match CI. Common Components will follow up with a `rust-toolchain.toml` to make this easier to keep in sync. # How to test the change? 1. Install hooks as above 2. Modify a `.rs` file and commit — `cargo fmt` runs automatically 3. Push — `cargo clippy` runs before the push goes through 4. Modify a `Cargo.toml` and commit — `dd-rust-license-tool check` runs
1 parent 0a3304c commit ec2fd4e

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
.claude/ @DataDog/apm-common-components-core
66
.clang-format @DataDog/libdatadog
7+
.pre-commit-config.yaml @DataDog/libdatadog-core
78
.codecov.yml @DataDog/apm-common-components-core
89
.cargo/* @DataDog/libdatadog-core
910
.config/nextest.toml @DataDog/apm-common-components-core

.pre-commit-config.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Pre-commit configuration for libdatadog
2+
#
3+
# Install (GIT_CONFIG_GLOBAL=/dev/null works around DD core.hooksPath):
4+
# GIT_CONFIG_GLOBAL=/dev/null pre-commit install
5+
# GIT_CONFIG_GLOBAL=/dev/null pre-commit install --hook-type pre-push
6+
#
7+
# Mirrors CI checks from .github/workflows/lint.yml:
8+
# pre-commit: cargo +nightly-2026-02-08 fmt --all
9+
# pre-push: cargo clippy --workspace --all-targets --all-features -- -D warnings
10+
# pre-commit: dd-rust-license-tool check (on dependency/license file changes)
11+
repos:
12+
- repo: local
13+
hooks:
14+
- id: cargo-fmt
15+
name: cargo fmt
16+
language: system
17+
# Pinned to match CI (.github/workflows/lint.yml). Keep this in sync.
18+
entry: cargo +nightly-2026-02-08 fmt --all --
19+
types: [rust]
20+
pass_filenames: false
21+
22+
- id: cargo-clippy
23+
name: cargo clippy
24+
language: system
25+
entry: cargo clippy --workspace --all-targets --all-features -- -D warnings
26+
types: [rust]
27+
pass_filenames: false
28+
stages: [pre-push]
29+
30+
- id: license-3rdparty
31+
name: dd-rust-license-tool check
32+
language: system
33+
# CI pins version 1.0.6 — install with: cargo install dd-rust-license-tool --version 1.0.6
34+
entry: dd-rust-license-tool check
35+
files: (Cargo\.toml|Cargo\.lock|license-tool\.toml|LICENSE-3rdparty\.csv)$
36+
pass_filenames: false

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ If you'd like CI to automatically format your code and commit the changes to you
9191
label to your pull request. This will trigger a one-time formatting commit if any changes are needed. If you push
9292
additional commits after labeling, remove and re-add the label to re-run formatting.
9393

94+
Optionally, you can install [pre-commit](https://pre-commit.com/) hooks to run formatting and clippy checks locally
95+
before they hit CI. See `.pre-commit-config.yaml` for setup instructions.
96+
9497
## Commit Message Guidelines
9598

9699
This project uses [Conventional Commits](https://www.conventionalcommits.org/) for commit messages and pull request titles.

0 commit comments

Comments
 (0)