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

Chore/add clippy-stacks alias #5734

Merged
merged 7 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
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"
obycode marked this conversation as resolved.
Show resolved Hide resolved
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
jferrant marked this conversation as resolved.
Show resolved Hide resolved
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