Skip to content

Commit

Permalink
tools/ruff.sh: Allow restricting checking to specific subtrees
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterNerlich authored Feb 4, 2025
1 parent 1753a82 commit ceca21f
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions tools/ruff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,37 @@ source "$(dirname "${BASH_SOURCE[0]}")/_functions.sh"

require_installed

PATHS=()

# Parse given command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
*) PATHS+=("$1");shift;;
esac
done

if [[ -n "${PATHS}" ]]; then
# Check whether paths exist
for p in "${PATHS[@]}"; do
if [[ -e "${p%%::*}" ]]; then
RUFF_ARGS+=("${p}")
elif [[ -n "${p}" ]]; then
# If the path does not exist but was non-zero, show an error
echo -e "${p%%::*}: No such file or directory" | print_error
exit 1
fi
done
else
PATHS=($BASE_DIR)
fi

# Run ruff as a pre-commit hook
run_as_precommit "ruff check" "$@"
run_as_precommit "ruff format --check" "$@"

# Run ruff
echo "Starting code linting and formatting with ruff..." | print_info
ruff check --fix "${BASE_DIR}" || true
ruff format "${BASE_DIR}"
ruff check --fix "${PATHS[@]}" || true
ruff format "${PATHS[@]}"

echo "✔ Code formatting & linting finished" | print_success

0 comments on commit ceca21f

Please sign in to comment.