Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 1 addition & 6 deletions .claude/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ After changing Rust code (`*.rs`) follow these steps in order:
2. **Lint** by running the following from the root of the repository:
```
cd "$(git rev-parse --show-toplevel)"
cargo clippy --all-features <CRATES> -- \
-D warnings \
-D clippy::all \
-D clippy::mem_forget \
-D clippy::unseparated_literal_suffix \
-A clippy::uninlined_format_args
ci/scripts/cargo-clippy.sh --fix --allow-dirty <CRATES>
```
where `<CRATES>` is a space separated list of
`-p <CRATE>` options for all modified crates.
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci-pr-only.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ jobs:
bazel run :rustfmt
bazel run :gazelle

ci/scripts/cargo-clippy.sh --fix --allow-dirty

git add --all
git status
if ! git diff --cached --quiet; then
Expand Down
33 changes: 33 additions & 0 deletions ci/scripts/cargo-clippy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -euo pipefail

clippy_args=(
# Do not modify Cargo.lock.
--locked

# For comprehensiveness.
--workspace
--all-features
--all-targets

# Don't stop at the first error, but rather, report ALL of them.
--keep-going

# Everything after this is forwarded from cargo to the clippy binary itself.
--

# Be strict.
--deny warnings
--deny clippy::all

# Ban std::mem::forget, because it is a memory leak hazard.
--deny clippy::mem_forget

# Require 42_u64, as opposed to 42u64. Because spaces good.
--deny clippy::unseparated_literal_suffix

# Allow format!("{}", x) instead of format!("{x}").
--allow clippy::uninlined_format_args
)

exec cargo clippy "$@" "${clippy_args[@]}"
51 changes: 11 additions & 40 deletions ci/scripts/rust-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,21 @@ cd "${CI_PROJECT_DIR:-$(git rev-parse --show-toplevel)}"

cargo fmt -- --check

clippy_args=(
# Do not modify Cargo.lock.
--locked

# For comprehensiveness.
--all-features
--workspace
--all-targets

# Don't stop at the first error, but rather, report ALL of them.
--keep-going

# Everything after this is forwarded from cargo to the clippy binary itself.
--
if ! ci/scripts/cargo-clippy.sh; then
# Don't just explode: provide a solution. Our job is to provide
# solid gold, not raw ore.
cat <<EOF

# Be strict.
--deny warnings
--deny clippy::all
========================================
$(printf '\033[1;31m')Clippy violations found!$(printf '\033[0m')

# Ban std::mem::forget, because it is a memory leak hazard.
--deny clippy::mem_forget
$(printf '\033[1;32m')To automatically fix many of these, run:

# Require 42_u64, as opposed to 42u64. Because spaces good.
--deny clippy::unseparated_literal_suffix
ci/scripts/cargo-clippy.sh --fix --allow-dirty$(printf '\033[0m')

# Allow format!("{}", x) instead of format!("{x}").
--allow clippy::uninlined_format_args
)
if ! cargo clippy "${clippy_args[@]}"; then
# Don't just explode: provide a solution. Our job is to provide
# solid gold, not raw ore.
echo ""
echo "========================================"
echo -ne "\033[1;31m" # Start red.
echo "Clippy violations found!"
echo -ne "\033[0m" # Clear formatting.
echo ""
echo -ne "\033[1;32m" # Start green.
echo "To automatically fix many of these, run:"
echo ""
echo " cargo clippy --fix ${clippy_args[@]}"
echo -ne "\033[0m" # Clear formatting.
echo ""
echo "========================================"
On PRs this will be run automatically by the 'autofix' job.
========================================
EOF
exit 1
fi

Expand Down
Loading