|
| 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