Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New helper script to run fast lints and pre-push hook that runs it #3949

Merged
merged 22 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ Configure your editor to run `cargo fmt` on save. Also configure it to strip tra

To check everything in one go, run `./scripts/check.sh`. `check.sh` should ideally check approximately the same things as our CI.

### Linting
Prior to pushing changes to a PR, at a minimum, you should always run `just fast-lint`. This is designed to run
in a few seconds and should catch the more trivial issues to avoid wasting CI time.

### Hooks
We recommend adding the rerun pre-push hook to your local checkout, which among other-things will run
`just fast-lint` for you.

To install the hooks, simply copy them into the `.git/hooks` directory of your local checkout.
```
cp hooks/pre-push .git/hooks/pre-push
chmod +x .git/hooks/pre-push
Copy link
Member

Choose a reason for hiding this comment

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

why not chmod +x hooks/pre-push already?

Copy link
Member Author

Choose a reason for hiding this comment

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

It generally should be, though I've definitely seen edge-cases across OS's and git configurations where that isn't guaranteed.

```
or if you prefer you can configure git to use this directory as the hooks directory:
```
git config core.hooksPath hooks
```

### Optional
You can use [bacon](https://github.com/Canop/bacon) to automatically check your code on each save. For instance, running just `bacon` will re-run `cargo cranky` each time you change a rust file. See [`bacon.toml`](bacon.toml) for more.

Expand Down
16 changes: 16 additions & 0 deletions hooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Hooks
This folder contains the official rerun githooks.

Each hook is designed to call through to a corresponding hook in the scripts directory.
- `pre-push` -> `scripts/pre-push.sh`

### Installation
To install the hooks, simply copy them into the `.git/hooks` directory of your local checkout.
```
cp hooks/pre-push .git/hooks/pre-push
chmod +x .git/hooks/pre-push
```
or if you prefer you can configure git to use this directory as the hooks directory:
```
git config core.hooksPath hooks
```
Comment on lines +13 to +16
Copy link
Member

Choose a reason for hiding this comment

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

Nice. TIL.

12 changes: 12 additions & 0 deletions hooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# This is a shim to call through to the managed pre-push hook.
# See: hooks/README.md for more details.
repo_root=$(git rev-parse --show-toplevel)
pre_push_hook=$repo_root/scripts/pre-push.sh
if [ -f "$pre_push_hook" ]; then
exec $pre_push_hook "$@"
else
echo "The pre-push hook appears to be missing from: $pre_push_hook -- Skipping."
exit 0
fi
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ format: cpp-format toml-format py-format
# Lint all of our code
lint: toml-lint py-lint rs-lint

# Run the fast versions of our linters
fast-lint *ARGS:
pixi run fast-lint {{ARGS}}

### C and C++

# Clear the C++ build directories
Expand Down
Loading
Loading