ladybird/Meta/lint-python.sh
Timothy Flynn c204149bbd
Some checks are pending
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Meta+CI: Enforce python linting with ruff
We could use flake8 for linting, but ruff is compatible with black
formatting out-of-the-box. It also seems to catch more than flake8,
such as unnecessary f-strings.
2025-06-09 11:25:14 -04:00

48 lines
933 B
Bash
Executable file

#!/usr/bin/env bash
set -e
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
cd "${script_path}/.." || exit 1
overwrite=0
if [ "$#" -gt "0" ]; then
if [ "--overwrite-inplace" = "$1" ] ; then
overwrite=1
shift
fi
fi
if [ "$#" -eq "0" ]; then
files=()
while IFS= read -r file; do
files+=("$file")
done < <(
git ls-files '*.py'
)
else
files=()
for file in "$@"; do
if [[ "${file}" == *".py" ]]; then
files+=("${file}")
fi
done
fi
if (( ${#files[@]} )); then
if ! command -v ruff >/dev/null 2>&1 ; then
echo "Please install ruff: pip3 install ruff"
exit 1
fi
if [[ ${overwrite} -eq 0 ]] ; then
ruff check "${files[@]}"
ruff format --check "${files[@]}"
else
ruff check --fix "${files[@]}"
ruff format "${files[@]}"
fi
else
echo "No py files to check."
fi