mirror of
https://github.com/langchain-ai/datafusion.git
synced 2026-07-18 13:15:59 -04:00
6bf5e98b59
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> Part of https://github.com/apache/datafusion/issues/19227 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> See issue for details. The existing script `./dev/rust_lint.sh` do checks for all non-functional tests include formater/clippy checks. Some check tools support auto fix options, so this PR add an option to the lint scripts to perform auto-fixes. Now `./dev/rust_lint.sh --write --allow-dirty` can perform auto-fixes for all linter etc. violations ``` yongting@Yongtings-MacBook-Pro-2 ~/C/datafusion (auto-fix)> ./dev/rust_lint.sh --help Usage: ./dev/rust_lint.sh [--write] [--allow-dirty] Runs the local Rust lint suite similar to CI. --write Run formatters, clippy and other non-functional checks in best-effort write/fix mode (requires a clean git worktree, no uncommitted changes; some checks are test-only and ignore this flag). --allow-dirty Allow `--write` to run even when the git worktree has uncommitted changes. ``` ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> - Adds `[--write] [--allow-dirty]` flag to `rust_lint.sh` to support auto fixes - `rust_lint.sh` consists of several sub-scripts like `rust_fmt.sh`, they're all extended with auto-fix feature through `--write` flag, and the `rust_lint.sh` is optionally calling them with an additional flag for auto fixes. - Clean up `rust_lint.sh` ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Yes, commit 8c99417929fcf133423dd3392f1939ab13a0bc93 intentionally introduced one violation for each available lint check, and the auto-fix command is able to fix all of them. The test may not be comprehensive, but it provides a reasonable starting point. We can begin using this script now and iterate on it if we discover cases where the auto-fix does not behave correctly. ## Are there any user-facing changes? No <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
69 lines
1.8 KiB
Bash
Executable File
69 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
# or more contributor license agreements. See the NOTICE file
|
|
# distributed with this work for additional information
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
# to you under the Apache License, Version 2.0 (the
|
|
# "License"); you may not use this file except in compliance
|
|
# with the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing,
|
|
# software distributed under the License is distributed on an
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
# KIND, either express or implied. See the License for the
|
|
# specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
|
|
source "${SCRIPT_DIR}/utils/git.sh"
|
|
|
|
MODE="check"
|
|
ALLOW_DIRTY=0
|
|
|
|
usage() {
|
|
cat >&2 <<EOF
|
|
Usage: $0 [--write] [--allow-dirty]
|
|
|
|
Runs \`cargo fmt --all -- --check\` by default to verify Rust formatting.
|
|
--write Run \`cargo fmt --all\` to auto-fix formatting (requires a clean git worktree, no uncommitted changes).
|
|
--allow-dirty Allow \`--write\` to run even when the git worktree has uncommitted changes.
|
|
EOF
|
|
exit 1
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--write)
|
|
MODE="write"
|
|
;;
|
|
--allow-dirty)
|
|
ALLOW_DIRTY=1
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
;;
|
|
*)
|
|
usage
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [[ "$MODE" == "write" && $ALLOW_DIRTY -eq 0 ]]; then
|
|
require_clean_work_tree "$SCRIPT_NAME" || exit 1
|
|
fi
|
|
|
|
if [[ "$MODE" == "write" ]]; then
|
|
echo "[${SCRIPT_NAME}] \`cargo fmt --all\`"
|
|
cargo fmt --all
|
|
else
|
|
echo "[${SCRIPT_NAME}] \`cargo fmt --all -- --check\`"
|
|
cargo fmt --all -- --check
|
|
fi
|