chore: Add pre-push hook to run clippy #1400

Merged
ginger merged 7 commits from trashpanda/continuwuity:trashpanda/commit-clippy into main 2026-03-04 15:10:48 +00:00
Contributor

This pull request forces clippy to run on every push and deny any warnings that are emitted, ensuring the author fixes any lints before pushing.

Pull request checklist:

  • This pull request targets the main branch, and the branch is named something other than
    main.
  • I have written an appropriate pull request title and my description is clear.
  • I understand I am responsible for the contents of this pull request.
  • I have followed the contributing guidelines:
This pull request forces clippy to run on every push and deny any warnings that are emitted, ensuring the author fixes any lints before pushing. **Pull request checklist:** <!-- You need to complete these before your PR can be considered. If you aren't sure about some, feel free to ask for clarification in #dev:continuwuity.org. --> - [x] This pull request targets the `main` branch, and the branch is named something other than `main`. - [x] I have written an appropriate pull request title and my description is clear. - [x] I understand I am responsible for the contents of this pull request. - I have followed the [contributing guidelines][c1]: - [x] My contribution follows the [code style][c2], if applicable. - [x] I ran [pre-commit checks][c1pc] before opening/drafting this pull request. - [x] I have [tested my contribution][c1t] (or proof-read it for documentation-only changes) myself, if applicable. This includes ensuring code compiles. - [x] My commit messages follow the [commit message format][c1cm] and are descriptive. - [ ] I have written a [news fragment][n1] for this PR, if applicable<!--(can be done after hitting open!)-->. <!-- Notes on these requirements: - While not required, we encourage you to sign your commits with GPG or SSH to attest the authenticity of your changes. - While we allow LLM-assisted contributions, we do not appreciate contributions that are low quality, which is typical of machine-generated contributions that have not had a lot of love and care from a human. Please do not open a PR if all you have done is asked ChatGPT to tidy up the codebase with a +-100,000 diff. - In the case of code style violations, reviewers may leave review comments/change requests indicating what the ideal change would look like. For example, a reviewer may suggest you lower a log level, or use `match` instead of `if/else` etc. - In the case of code style violations, pre-commit check failures, minor things like typos/spelling errors, and in some cases commit format violations, reviewers may modify your branch directly, typically by making changes and adding a commit. Particularly in the latter case, a reviewer may rebase your commits to squash "spammy" ones (like "fix", "fix", "actually fix"), and reword commit messages that don't satisfy the format. - Pull requests MUST pass the `Checks` CI workflows to be capable of being merged. This can only be bypassed in exceptional circumstances. If your CI flakes, let us know in matrix:r/dev:continuwuity.org. - Pull requests have to be based on the latest `main` commit before being merged. If the main branch changes while you're making your changes, you should make sure you rebase on main before opening a PR. Your branch will be rebased on main before it is merged if it has fallen behind. - We typically only do fast-forward merges, so your entire commit log will be included. Once in main, it's difficult to get out cleanly, so put on your best dress, smile for the cameras! --> [c1]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md [c2]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/docs/development/code_style.mdx [c1pc]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#pre-commit-checks [c1t]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#running-tests-locally [c1cm]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#commit-messages [n1]: https://towncrier.readthedocs.io/en/stable/tutorial.html#creating-news-fragments
fix: Remove erroneous addition of pre-push stage to default_stages
All checks were successful
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 4m2s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 14m9s
f32ff1889b
Member

While this seems worthwhile for contributors getting into the Rust code, and would technically help save a bit of CI resources if the corresponding CI workflow were removed at the same time, this would seem to imply a required clippy run even for docs-only changes (as well as any other change not directly impacting the Rust source). Is that interpretation correct?

While this seems worthwhile for contributors getting into the Rust code, and would technically help save a bit of CI resources if the corresponding CI workflow were removed at the same time, this would seem to imply a required clippy run even for docs-only changes (as well as any other change not directly impacting the Rust source). Is that interpretation correct?
Author
Contributor

Yes, this would run clippy even for docs-only changes. It seems that prefligit isn't able to detect changed files from unpushed commits, or I could not find any feature that would allow that, and it would skip the clippy run.

Yes, this would run clippy even for docs-only changes. It seems that prefligit isn't able to detect changed files from unpushed commits, or I could not find any feature that would allow that, and it would skip the clippy run.
Contributor

could you also add pkgs.clippy to the shell.nix, so people who use the devshell can run this too <3

could you also add `pkgs.clippy` to the shell.nix, so people who use the devshell can run this too <3
fix: Prevent clippy from running on changes that don't include rust code
Some checks failed
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 9m10s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 17m45s
98902528d4
@ -48,0 +57,4 @@
then
cargo +nightly clippy -- -D warnings;
fi
'
Author
Contributor

This could (and probably should?) just be a separate file, but this also does work.

This could (and probably should?) just be a separate file, but this also does work.
trashpanda marked this conversation as resolved
Contributor

My one concern is this slows down a traditionally light-weight commit hook that was more geared toward formatting and light-weight checks than heavy-duty rust compilation and related linting/test execution.

If this made it in, I would probably disable it then tell git to ignore index changes to that file so I wouldn't have to re-commit my light-weight version, since I typically want to run them separately, in isolation, not monolithically.

My one concern is this slows down a traditionally light-weight commit hook that was more geared toward formatting and light-weight checks than heavy-duty rust compilation and related linting/test execution. If this made it in, I would probably disable it then tell git to ignore index changes to that file so I wouldn't have to re-commit my light-weight version, since I typically want to run them separately, in isolation, not monolithically.
Author
Contributor

@gamesguru wrote in #1400 (comment):

My one concern is this slows down a traditionally light-weight commit hook...

This hook is only run before pushing to the server, and afaict is the only hook that will run in that stage anyways.

@gamesguru wrote in https://forgejo.ellis.link/continuwuation/continuwuity/pulls/1400#issuecomment-24519: > My one concern is this slows down a traditionally light-weight commit hook... This hook is only run before pushing to the server, and afaict is the only hook that will run in that stage anyways.
@ -48,0 +52,4 @@
- id: cargo-clippy
name: cargo clippy
entry: >
sh -c '
Owner

Doesn't pre-commit have a built in way to say 'only run this on rs files?

Doesn't pre-commit have a built in way to say 'only run this on `rs` files?
Author
Contributor

Yes, but it didn't appear to be working during the pre-push hook in my testing with prefligit.

Yes, but it didn't appear to be working during the pre-push hook in my testing with prefligit.
Author
Contributor

a proof of concept of the pre-push hook not running:

continuwuity ) git diff @{u} HEAD
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index d4ddfac0..ff4a0046 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -59,7 +59,8 @@ repos:
             fi
           '
         language: system
+        types: [rust]
         pass_filenames: false
-        always_run: true
+        always_run: false
         stages:
           - pre-push
diff --git a/src/service/client/mod.rs b/src/service/client/mod.rs
index bd5853c9..ca842622 100644
--- a/src/service/client/mod.rs
+++ b/src/service/client/mod.rs
@@ -39,7 +39,8 @@ fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
                let url_preview_user_agent = config
                        .url_preview_user_agent
                        .clone()
-                       .unwrap_or_else(|| conduwuit::version::user_agent().to_owned());
+                       // we have a little fun >:3
+                       .unwrap_or_else(|| conduwuit::version::user_agent().to_string());
 
                Ok(Arc::new(Self {
                        default: base(config)?
continuwuity ) git push --dry-run
Confirm user presence for key ECDSA-SK SHA256:9vnRjRy+j3Jk7qUgWFWUVx0nMc4z0DJGzAfZ/88vjko
User presence confirmed
detect destroyed symlinks............................(no files to check)Skipped
fix end of files.....................................(no files to check)Skipped
trim trailing whitespace.............................(no files to check)Skipped
check for added large files..........................(no files to check)Skipped
typos................................................(no files to check)Skipped
cargo clippy.........................................(no files to check)Skipped
To ssh://forgejo.ellis.link/trashpanda/continuwuity.git
   98902528..bd397d01  trashpanda/commit-clippy -> trashpanda/commit-clippy
a proof of concept of the pre-push hook not running: ``` continuwuity ) git diff @{u} HEAD diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d4ddfac0..ff4a0046 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -59,7 +59,8 @@ repos: fi ' language: system + types: [rust] pass_filenames: false - always_run: true + always_run: false stages: - pre-push diff --git a/src/service/client/mod.rs b/src/service/client/mod.rs index bd5853c9..ca842622 100644 --- a/src/service/client/mod.rs +++ b/src/service/client/mod.rs @@ -39,7 +39,8 @@ fn build(args: crate::Args<'_>) -> Result<Arc<Self>> { let url_preview_user_agent = config .url_preview_user_agent .clone() - .unwrap_or_else(|| conduwuit::version::user_agent().to_owned()); + // we have a little fun >:3 + .unwrap_or_else(|| conduwuit::version::user_agent().to_string()); Ok(Arc::new(Self { default: base(config)? continuwuity ) git push --dry-run Confirm user presence for key ECDSA-SK SHA256:9vnRjRy+j3Jk7qUgWFWUVx0nMc4z0DJGzAfZ/88vjko User presence confirmed detect destroyed symlinks............................(no files to check)Skipped fix end of files.....................................(no files to check)Skipped trim trailing whitespace.............................(no files to check)Skipped check for added large files..........................(no files to check)Skipped typos................................................(no files to check)Skipped cargo clippy.........................................(no files to check)Skipped To ssh://forgejo.ellis.link/trashpanda/continuwuity.git 98902528..bd397d01 trashpanda/commit-clippy -> trashpanda/commit-clippy ```
Owner

I'm not sure what's up with that then - mayve always_run shoudn't be set?

  - repo: local
    hooks:
      - id: cargo-fmt
        name: cargo fmt
        entry: cargo +nightly fmt --
        language: system
        types: [rust]
        pass_filenames: false
        stages:
            - pre-commit

triggers correctly at least?
I'll have a check when I have time

I'm not sure what's up with that then - mayve always_run shoudn't be set? ```yaml - repo: local hooks: - id: cargo-fmt name: cargo fmt entry: cargo +nightly fmt -- language: system types: [rust] pass_filenames: false stages: - pre-commit ``` triggers correctly at least? I'll have a check when I have time
Author
Contributor

I'm thinking it has to do with the stage it runs in. The clippy hook I added is run in the pre-push stage, after all files have been committed. The hook was working when it was a pre-commit hook.

I'm thinking it has to do with the stage it runs in. The clippy hook I added is run in the pre-push stage, after all files have been committed. The hook was working when it was a pre-commit hook.
Owner

Ah, that would make a lot of sense.

Ah, that would make a lot of sense.
Owner

I can't reproduce this with prek or pre-commit:

⠀jade@Mac ~/Code/continuwuity   main ≡ SIGINT - 130
ZSH⠀> git push --dry-run
detect destroyed symlinks................................................Passed
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
check for added large files..............................................Passed
typos....................................................................Passed
cargo clippy.............................................................Failed
- hook id: cargo-clippy
- exit code: 101

  Compiling conduwuit_build_metadata v0.5.5 (/Users/jade/Code/continuwuity/src/build_metadata)
     Compiling conduwuit_macros v0.5.5 (/Users/jade/Code/continuwuity/src/macros)
      Checking conduwuit_core v0.5.5 (/Users/jade/Code/continuwuity/src/core)
      Checking conduwuit_database v0.5.5 (/Users/jade/Code/continuwuity/src/database)
      Checking conduwuit_service v0.5.5 (/Users/jade/Code/continuwuity/src/service)
  error: `to_string()` called on a `&str`
    --> src/service/client/mod.rs:42:23
     |
  42 |             .unwrap_or_else(|| conduwuit::version::user_agent().to_string());
     |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `conduwuit::version::user_agent().to_owned()`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#str_to_string
     = note: `-D clippy::str-to-string` implied by `-D warnings`
     = help: to override `-D warnings` add `#[allow(clippy::str_to_string)]`

  error: could not compile `conduwuit_service` (lib) due to 1 previous error
error: failed to push some refs to 'ssh://forgejo.ellis.link/continuwuation/continuwuity.git'
⠀jade@Mac ~/Code/continuwuity   main ↑1
ZSH⠀> pre-commit install -f
pre-commit installed at .git/hooks/pre-commit
pre-commit installed at .git/hooks/commit-msg
pre-commit installed at .git/hooks/pre-push
⠀jade@Mac ~/Code/continuwuity   main ↑1
ZSH⠀> git push --dry-run
fatal: bad object fbeb5bf186c7c9346e23e68e594d9a6aed0fc2df
[INFO] Initializing environment for https://github.com/crate-ci/typos.
[INFO] Initializing environment for https://github.com/crate-ci/committed.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/crate-ci/typos.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
detect destroyed symlinks................................................Passed
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
check for added large files..............................................Passed
typos....................................................................Passed
cargo clippy.............................................................Failed
- hook id: cargo-clippy
- exit code: 101

    Checking conduwuit_service v0.5.5 (/Users/jade/Code/continuwuity/src/service)
error: `to_string()` called on a `&str`
  --> src/service/client/mod.rs:42:23
   |
42 |             .unwrap_or_else(|| conduwuit::version::user_agent().to_string());
   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `conduwuit::version::user_agent().to_owned()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#str_to_string
   = note: `-D clippy::str-to-string` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::str_to_string)]`

error: could not compile `conduwuit_service` (lib) due to 1 previous error

error: failed to push some refs to 'ssh://forgejo.ellis.link/continuwuation/continuwuity.git'
.pre-commit-config.yaml --- 1/2 --- YAML
 1  1 default_install_hook_types:
 2  2   - pre-commit
 3  3   - commit-msg
 .  4   - pre-push
 4  5 default_stages:
 5  6   - pre-commit
 6  7   - manual

.pre-commit-config.yaml --- 2/2 --- YAML
46 47         stages:
47 48             - pre-commit
   49
   50       - id: cargo-clippy
   51         name: cargo clippy
   52         entry: cargo clippy -- -D warnings
   53         pass_filenames: false
   54         language: system
   55         types: [rust]
   56         stages:
   57             - pre-push

(on macos)

Likely a bug upstream?

I can't reproduce this with prek or pre-commit: ``` ⠀jade@Mac ~/Code/continuwuity  main ≡ SIGINT - 130 ZSH⠀> git push --dry-run detect destroyed symlinks................................................Passed fix end of files.........................................................Passed trim trailing whitespace.................................................Passed check for added large files..............................................Passed typos....................................................................Passed cargo clippy.............................................................Failed - hook id: cargo-clippy - exit code: 101 Compiling conduwuit_build_metadata v0.5.5 (/Users/jade/Code/continuwuity/src/build_metadata) Compiling conduwuit_macros v0.5.5 (/Users/jade/Code/continuwuity/src/macros) Checking conduwuit_core v0.5.5 (/Users/jade/Code/continuwuity/src/core) Checking conduwuit_database v0.5.5 (/Users/jade/Code/continuwuity/src/database) Checking conduwuit_service v0.5.5 (/Users/jade/Code/continuwuity/src/service) error: `to_string()` called on a `&str` --> src/service/client/mod.rs:42:23 | 42 | .unwrap_or_else(|| conduwuit::version::user_agent().to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `conduwuit::version::user_agent().to_owned()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#str_to_string = note: `-D clippy::str-to-string` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::str_to_string)]` error: could not compile `conduwuit_service` (lib) due to 1 previous error error: failed to push some refs to 'ssh://forgejo.ellis.link/continuwuation/continuwuity.git' ⠀jade@Mac ~/Code/continuwuity  main ↑1 ZSH⠀> pre-commit install -f pre-commit installed at .git/hooks/pre-commit pre-commit installed at .git/hooks/commit-msg pre-commit installed at .git/hooks/pre-push ⠀jade@Mac ~/Code/continuwuity  main ↑1 ZSH⠀> git push --dry-run fatal: bad object fbeb5bf186c7c9346e23e68e594d9a6aed0fc2df [INFO] Initializing environment for https://github.com/crate-ci/typos. [INFO] Initializing environment for https://github.com/crate-ci/committed. [INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... [INFO] Installing environment for https://github.com/crate-ci/typos. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... detect destroyed symlinks................................................Passed fix end of files.........................................................Passed trim trailing whitespace.................................................Passed check for added large files..............................................Passed typos....................................................................Passed cargo clippy.............................................................Failed - hook id: cargo-clippy - exit code: 101 Checking conduwuit_service v0.5.5 (/Users/jade/Code/continuwuity/src/service) error: `to_string()` called on a `&str` --> src/service/client/mod.rs:42:23 | 42 | .unwrap_or_else(|| conduwuit::version::user_agent().to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `conduwuit::version::user_agent().to_owned()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#str_to_string = note: `-D clippy::str-to-string` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::str_to_string)]` error: could not compile `conduwuit_service` (lib) due to 1 previous error error: failed to push some refs to 'ssh://forgejo.ellis.link/continuwuation/continuwuity.git' ``` ``` .pre-commit-config.yaml --- 1/2 --- YAML 1 1 default_install_hook_types: 2 2 - pre-commit 3 3 - commit-msg . 4 - pre-push 4 5 default_stages: 5 6 - pre-commit 6 7 - manual .pre-commit-config.yaml --- 2/2 --- YAML 46 47 stages: 47 48 - pre-commit 49 50 - id: cargo-clippy 51 name: cargo clippy 52 entry: cargo clippy -- -D warnings 53 pass_filenames: false 54 language: system 55 types: [rust] 56 stages: 57 - pre-push ``` (on macos) Likely a bug upstream?
Author
Contributor

I'll dig into this tonight. I haven't tried the original pre-commit, it may just be that prefligit has some obscure bug on Linux or even something to do with my system configuration.

I'll dig into this tonight. I haven't tried the original pre-commit, it may just be that prefligit has some obscure bug on Linux or even something to do with my system configuration.
Contributor

@trashpanda wrote in #1400 (comment):

@gamesguru wrote in #1400 (comment):

My one concern is this slows down a traditionally light-weight commit hook...

This hook is only run before pushing to the server, and afaict is the only hook that will run in that stage anyways.

fair then, apologies for the misunderstanding.

just wanted to make sure anything "heavy" pre-commit had a clear way to opt-out of or disable if needed. Carry on

@trashpanda wrote in https://forgejo.ellis.link/continuwuation/continuwuity/pulls/1400#issuecomment-24520: > @gamesguru wrote in #1400 (comment): > > > My one concern is this slows down a traditionally light-weight commit hook... > > This hook is only run before pushing to the server, and afaict is the only hook that will run in that stage anyways. fair then, apologies for the misunderstanding. just wanted to make sure anything "heavy" pre-commit had a clear way to opt-out of or disable if needed. Carry on
fix: Lessen complexity of test expression
All checks were successful
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Update flake hashes / update-flake-hashes (pull_request) Successful in 1m6s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 2m7s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 7m16s
f9f8599647
Author
Contributor

Anything I can clear up to help this get merged?

Anything I can clear up to help this get merged?
Owner

The only thing would be that we use the default clippy toolchain to avoid cache thrashing, but it's not merged yet becaues we haven't done a merge run yet. Don't sweat 😅

The only thing would be that we use the default clippy toolchain to avoid cache thrashing, but it's not merged yet becaues we haven't done a merge run yet. Don't sweat 😅
fix(pre-commit): Remove unnecessary test expression
All checks were successful
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 15m17s
Update flake hashes / update-flake-hashes (pull_request) Successful in 4m29s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 20m54s
9e69e082ed
fix(pre-commit): Use default clippy toolchain to avoid cache thrashing
Some checks failed
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 10m5s
Update flake hashes / update-flake-hashes (pull_request) Successful in 4m18s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 14m44s
8f6070df1f
Jade approved these changes 2026-02-25 17:15:48 +00:00
Jade force-pushed trashpanda/commit-clippy from 8f6070df1f
Some checks failed
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 10m5s
Update flake hashes / update-flake-hashes (pull_request) Successful in 4m18s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 14m44s
to e061abc431
Some checks failed
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 3m48s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 20m29s
2026-02-25 17:16:00 +00:00
Compare
ginger merged commit c6943ae683 into main 2026-03-04 15:10:48 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
5 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
continuwuation/continuwuity!1400
No description provided.