chore: add pre-commit config for local Rust lint checks#1871
Conversation
Mirrors CI lint checks for local development: - pre-commit: cargo fmt (nightly) and dd-rust-license-tool check - pre-push: cargo clippy --workspace
There was a problem hiding this comment.
Pull request overview
Adds an opt-in pre-commit configuration to run key Rust linting checks locally (fmt, clippy, and 3rd-party license validation) to better align developer workflows with CI and reduce CI round-trips.
Changes:
- Introduce
.pre-commit-config.yamlwith local hooks forcargo fmt(nightly),cargo clippy(pre-push), anddd-rust-license-tool check(on Cargo file changes).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Clarify nightly pinning in header comment (CI pins nightly-2026-02-08) - Expand license check file filter to include license-tool.toml and LICENSE-3rdparty.csv - Add version comment for dd-rust-license-tool (CI pins 1.0.6)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1871 +/- ##
=======================================
Coverage 72.63% 72.63%
=======================================
Files 451 451
Lines 74687 74687
=======================================
+ Hits 54249 54250 +1
+ Misses 20438 20437 -1
🚀 New features to boost your workflow:
|
|
🎯 Code Coverage (details) 🔗 Commit SHA: 19cd971 | Docs | Datadog PR Page | Give us feedback! |
|
I am a fan of this. Totally not opposed for this to go in, especially since this is opt in |
Artifact Size Benchmark Reportaarch64-alpine-linux-musl
aarch64-unknown-linux-gnu
libdatadog-x64-windows
libdatadog-x86-windows
x86_64-alpine-linux-musl
x86_64-unknown-linux-gnu
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 23f46b1eba
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| - id: cargo-fmt | ||
| name: cargo fmt | ||
| language: system | ||
| entry: cargo +nightly fmt --all -- |
There was a problem hiding this comment.
When a developer's local nightly toolchain is newer or older than the CI-pinned nightly-2026-02-08 used in .github/workflows/lint.yml, this hook can rewrite files with a different rustfmt version than CI checks. That makes the local hook non-deterministic and can leave contributors with formatting that passes locally but is rejected by CI; use the same pinned toolchain here, e.g. +nightly-2026-02-08.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This is a good suggestion. Could you pin to nightly-2026-02-08 for now? I'll create a ticket for Common Components to follow up and setup a rust-toolchain.toml file for the repo to make managing this easier in the future.
|
No objections from me on introducing hooks. |
Pin to nightly-2026-02-08 so the hook can't produce formatting that diverges from .github/workflows/lint.yml. Also link the config from CONTRIBUTING.md so contributors can find it.
|
thanks @ekump I added your suggestions |
|
/merge |
|
View all feedbacks in Devflow UI.
This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
The expected merge time in
The merge request has been interrupted because the build 0 took longer than expected. The current limit for the base branch 'main' is 120 minutes. |
What does this PR do?
Adds a
.pre-commit-config.yamlthat mirrors CI lint checks for local development:cargo +nightly-2026-02-08 fmt --allanddd-rust-license-tool check(only on Cargo.toml/lock and license input changes)cargo clippy --workspace --all-targets --all-features -- -D warningsMotivation
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 (the Python tool), but it's a nice framework that's trivial to install, especially with
uv: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:
(
GIT_CONFIG_GLOBAL=/dev/nullworks around the DD globalcore.hooksPathsetting.)rustfmt is pinned to
nightly-2026-02-08to match CI. Common Components will follow up with arust-toolchain.tomlto make this easier to keep in sync.How to test the change?
.rsfile and commit —cargo fmtruns automaticallycargo clippyruns before the push goes throughCargo.tomland commit —dd-rust-license-tool checkruns