Skip to content

Commit

Permalink
Create clippy-stacks alias to run in CI and to run locally
Browse files Browse the repository at this point in the history
Signed-off-by: Jacinta Ferrant <jacinta@trustmachines.co>
  • Loading branch information
jferrant committed Jan 22, 2025
1 parent e0d3f3c commit b851d0f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[alias]
stacks-node = "run --package stacks-node --"
fmt-stacks = "fmt -- --config group_imports=StdExternalCrate,imports_granularity=Module"
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"

# Uncomment to improve performance slightly, at the cost of portability
# * Note that native binaries may not run on CPUs that are different from the build machine
Expand Down
15 changes: 1 addition & 14 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,8 @@ jobs:
name: Clippy Check
runs-on: ubuntu-latest
steps:
- name: Checkout the latest code
id: git_checkout
uses: actions/checkout@v3
- name: Define Rust Toolchain
id: define_rust_toolchain
run: echo "RUST_TOOLCHAIN=$(cat ./rust-toolchain)" >> $GITHUB_ENV
- name: Setup Rust Toolchain
id: setup_rust_toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
components: clippy
- name: Clippy
id: clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: -p libstackerdb -p stacks-signer -p pox-locking -p clarity -p libsigner -p stacks-common --no-deps --tests --all-features -- -D warnings
alias: "clippy-stacks"
20 changes: 19 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,24 @@ fix: incorporate unlocks in mempool admitter, #3623

### Recommended githooks

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

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

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

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

## Clippy Warnings

PRs will be checked against `clippy` and will _fail_ if any clippy warnings are generated.
Unfortunately, not all existing clippy warnings have been addressed throughout stacks-core, so arguments must be passed via the command line.
Therefore, we handle `clippy` configurations using a Cargo alias: `cargo clippy-stacks`

You can check what warnings need to be addressed locally via:

```bash
cargo clippy-stacks
```

## Comments

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

0 comments on commit b851d0f

Please sign in to comment.