Skip to content

Add a pre-commit hook mirroring CI's fmt and clippy checks - #1372

Open
ErwanLegrand wants to merge 1 commit into
RustAudio:masterfrom
ErwanLegrand:fix/pre-commit
Open

ErwanLegrand wants to merge 1 commit into
RustAudio:masterfrom
ErwanLegrand:fix/pre-commit

Conversation

@ErwanLegrand

Copy link
Copy Markdown
Contributor

It's all in the title. The aim is to increase the quality of submissions before CI even runs, obviously.

@ErwanLegrand ErwanLegrand changed the title chore: add a pre-commit hook mirroring CI's fmt and clippy checks Add a pre-commit hook mirroring CI's fmt and clippy checks Sep 19, 2026

@LastExceed LastExceed left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea! There are a few things I'd change though:

Comment thread .githooks/pre-commit Outdated
Comment on lines +2 to +5
# Pre-commit hook: runs the same fmt and clippy checks as CI's Code Quality workflow
# (`cargo fmt --all -- --check` and `cargo clippy --all -- -D warnings`), adapted to the
# local platform. CI additionally lints each supported target with per-platform feature
# sets (e.g. `--all-features` with the ASIO SDK on Windows), which a local hook cannot.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove this paragraph, as it seems a bit redundant. It does not matter here what CI does, and the hook itself seems simple enough to not require summary.

Comment thread .githooks/pre-commit Outdated
Comment on lines +12 to +15
# CI skips documentation-only changes (paths-ignore: "**.md", "docs/**", "LICENSE*", ".gitignore").
if ! git diff --cached --name-only --diff-filter=ACMR | grep -Eq '\.rs$|Cargo\.(toml|lock)$'; then
exit 0
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment implies a black-list, but the filter actually uses a white-list, so listing all the excluded files is redunant (and prone to be incomplete).

I also think that the filter is redundant in general, since there is no harm in running fmt and clippy on an unchanged code base, and who knows what kind of files not fitting the filter build.rs might depend on in the future.

Comment thread CONTRIBUTING.md Outdated
Comment on lines +34 to +36
CI's Code Quality workflow runs `cargo fmt --all -- --check` and `cargo clippy --all -- -D warnings`
(for each supported target/feature set). A pre-commit hook running the same commands on the local
platform is provided: install it once with

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before, I'd remove the CI part.

Also, perhaps emphasize that this is just an optional tool, not a requirement. Keeping all commits 100% compliant is not always feasible, or even desirable, and having to explicitly use --no-verify might constitute unnecessary friction for some people, especially those who prefer to do cleanup at the end of each branch instead of each commit (which is a common workflow that IMO is perfectly fine).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

@ErwanLegrand

Copy link
Copy Markdown
Contributor Author

I have made the changes as requested. Let me know if you find anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants