Skip to content

Commit b851d0f

Browse files
committed
Create clippy-stacks alias to run in CI and to run locally
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent e0d3f3c commit b851d0f

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

.cargo/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[alias]
22
stacks-node = "run --package stacks-node --"
33
fmt-stacks = "fmt -- --config group_imports=StdExternalCrate,imports_granularity=Module"
4+
clippy-stacks = "clippy -p libstackerdb -p stacks-signer -p pox-locking -p clarity -p libsigner -p stacks-common --no-deps --tests --all-features -- -D warnings"
45

56
# Uncomment to improve performance slightly, at the cost of portability
67
# * Note that native binaries may not run on CPUs that are different from the build machine

.github/workflows/clippy.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,8 @@ jobs:
2020
name: Clippy Check
2121
runs-on: ubuntu-latest
2222
steps:
23-
- name: Checkout the latest code
24-
id: git_checkout
25-
uses: actions/checkout@v3
26-
- name: Define Rust Toolchain
27-
id: define_rust_toolchain
28-
run: echo "RUST_TOOLCHAIN=$(cat ./rust-toolchain)" >> $GITHUB_ENV
29-
- name: Setup Rust Toolchain
30-
id: setup_rust_toolchain
31-
uses: actions-rust-lang/setup-rust-toolchain@v1
32-
with:
33-
toolchain: ${{ env.RUST_TOOLCHAIN }}
34-
components: clippy
3523
- name: Clippy
3624
id: clippy
3725
uses: actions-rs/clippy-check@v1
3826
with:
39-
token: ${{ secrets.GITHUB_TOKEN }}
40-
args: -p libstackerdb -p stacks-signer -p pox-locking -p clarity -p libsigner -p stacks-common --no-deps --tests --all-features -- -D warnings
27+
alias: "clippy-stacks"

CONTRIBUTING.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,24 @@ fix: incorporate unlocks in mempool admitter, #3623
8181

8282
### Recommended githooks
8383

84-
It is helpful to set up the pre-commit git hook set up, so that Rust formatting issues are caught before
84+
It is helpful to set up the pre-commit git hook set up, so that Rust formatting issues and clippy warnings are caught before
8585
you push your code. Follow these instruction to set it up:
8686

8787
1. Rename `.git/hooks/pre-commit.sample` to `.git/hooks/pre-commit`
8888
2. Change the content of `.git/hooks/pre-commit` to be the following
8989

9090
```sh
9191
#!/bin/sh
92+
# Format staged Rust files
9293
git diff --name-only --staged | grep '\.rs$' | xargs -P 8 -I {} rustfmt {} --edition 2021 --check --config group_imports=StdExternalCrate,imports_granularity=Module || (
9394
echo 'rustfmt failed: run "cargo fmt-stacks"';
9495
exit 1
9596
)
97+
# Run cargo clippy-stacks and fail the commit if there are any warnings
98+
if ! cargo clippy-stacks; then
99+
echo 'cargo clippy-stacks failed: fix the warnings and try again.';
100+
exit 1
101+
fi
96102
```
97103

98104
3. Make it executable by running `chmod +x .git/hooks/pre-commit`
@@ -387,6 +393,18 @@ You can automatically reformat your commit via:
387393
cargo fmt-stacks
388394
```
389395

396+
## Clippy Warnings
397+
398+
PRs will be checked against `clippy` and will _fail_ if any clippy warnings are generated.
399+
Unfortunately, not all existing clippy warnings have been addressed throughout stacks-core, so arguments must be passed via the command line.
400+
Therefore, we handle `clippy` configurations using a Cargo alias: `cargo clippy-stacks`
401+
402+
You can check what warnings need to be addressed locally via:
403+
404+
```bash
405+
cargo clippy-stacks
406+
```
407+
390408
## Comments
391409

392410
Comments are very important for the readability and correctness of the codebase. The purpose of comments is:

0 commit comments

Comments
 (0)