Skip to content

Commit 32189bf

Browse files
committed
Add cargo clippy check to git pre-commit check
1 parent d17d7f0 commit 32189bf

3 files changed

Lines changed: 77 additions & 5 deletions

File tree

.github/workflows/rust.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,7 @@ jobs:
153153
- name: Clippy
154154
if: matrix.name == 'clippy'
155155
run: |
156-
cargo clippy --workspace --all-targets --all-features -- -Dwarnings
157-
# Clean up clippy artifacts aggressively
158-
rm -rf target/debug/deps
159-
rm -rf target/debug/incremental
160-
rm -rf target/debug/build
156+
bash ci/scripts/cargo-clippy.sh --ci-cleanup
161157
162158
- name: Test
163159
if: matrix.name == 'test'

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,12 @@ repos:
6666
types_or: [c, c++]
6767
# Don't run on vendored files
6868
exclude: "^c/(sedona-geoarrow-c/src/geoarrow|sedona-geoarrow-c/src/nanoarrow|sedona-tg/src/tg)/.*"
69+
70+
- repo: local
71+
hooks:
72+
- id: cargo-clippy-fix-workspace
73+
name: cargo clippy fix workspace (best effort)
74+
entry: bash -c 'bash ci/scripts/cargo-clippy.sh --fix || true'
75+
language: system
76+
pass_filenames: false
77+
files: '(^|/)(Cargo\.toml|Cargo\.lock|.*\.rs)$'

ci/scripts/cargo-clippy.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
# Used by both CI and local pre-commit hooks.
21+
22+
set -uo pipefail
23+
24+
mode="check"
25+
ci_cleanup="false"
26+
27+
while [[ $# -gt 0 ]]; do
28+
case "$1" in
29+
--fix)
30+
mode="fix"
31+
shift
32+
;;
33+
--ci-cleanup)
34+
ci_cleanup="true"
35+
shift
36+
;;
37+
-h|--help)
38+
cat <<'EOF'
39+
Usage: ci/scripts/cargo-clippy.sh [--fix] [--ci-cleanup]
40+
41+
Options:
42+
--fix Run clippy with --fix (best-effort; may not fix all violations).
43+
--ci-cleanup Remove selected target/debug artifacts after clippy run.
44+
EOF
45+
exit 0
46+
;;
47+
*)
48+
echo "Unknown option: $1" >&2
49+
exit 2
50+
;;
51+
esac
52+
done
53+
54+
status=0
55+
if [[ "$mode" == "fix" ]]; then
56+
cargo clippy --fix --workspace --all-targets --all-features --allow-dirty --allow-staged -- -Dwarnings || status=$?
57+
else
58+
cargo clippy --workspace --all-targets --all-features -- -Dwarnings || status=$?
59+
fi
60+
61+
if [[ "$ci_cleanup" == "true" ]]; then
62+
rm -rf target/debug/deps
63+
rm -rf target/debug/incremental
64+
rm -rf target/debug/build
65+
fi
66+
67+
exit "$status"

0 commit comments

Comments
 (0)