2024-05-21 22:12:06 +08:00
|
|
|
#!/usr/bin/env bash
|
2022-09-05 19:18:40 +08:00
|
|
|
|
|
|
|
set -o errexit
|
|
|
|
|
2022-09-10 04:45:18 +08:00
|
|
|
help_and_exit() {
|
2024-03-03 05:56:37 +08:00
|
|
|
echo "Usage: ./lint.sh [-f|--fix]"
|
|
|
|
echo " -f, --fix fix issues if possible"
|
2022-09-10 04:45:18 +08:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ $# -gt 1 ]]; then
|
|
|
|
help_and_exit
|
|
|
|
fi
|
|
|
|
|
2024-03-03 05:56:37 +08:00
|
|
|
FIX=0
|
2022-09-10 04:45:18 +08:00
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
2024-05-21 22:12:06 +08:00
|
|
|
-f | --fix)
|
2024-03-03 05:56:37 +08:00
|
|
|
FIX=1
|
2022-09-10 04:45:18 +08:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
help_and_exit
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2023-08-06 22:37:56 +08:00
|
|
|
# Use Python virtual env for all programs used here
|
|
|
|
if [[ -z "${PWNDBG_VENV_PATH}" ]]; then
|
|
|
|
PWNDBG_VENV_PATH="./.venv"
|
|
|
|
fi
|
|
|
|
|
2024-05-21 22:12:06 +08:00
|
|
|
if [[ "${PWNDBG_VENV_PATH}" != "PWNDBG_PLEASE_SKIP_VENV" ]]; then
|
|
|
|
source "${PWNDBG_VENV_PATH}/bin/activate"
|
|
|
|
fi
|
2023-08-06 22:37:56 +08:00
|
|
|
|
2024-02-26 07:02:50 +08:00
|
|
|
set -o xtrace
|
|
|
|
|
2022-10-21 08:35:29 +08:00
|
|
|
LINT_FILES="pwndbg tests *.py"
|
2024-04-25 19:29:19 +08:00
|
|
|
LINT_TOOLS="isort ruff vermin mypy"
|
2022-10-22 17:15:05 +08:00
|
|
|
|
2022-10-26 08:46:53 +08:00
|
|
|
if ! type ${LINT_TOOLS} &> /dev/null; then
|
2024-03-12 00:42:16 +08:00
|
|
|
PIP_CMD="poetry install --with dev"
|
2022-10-22 17:15:05 +08:00
|
|
|
echo "Missing one of the following tools: ${LINT_TOOLS}"
|
|
|
|
echo "Running '${PIP_CMD}'"
|
|
|
|
|
|
|
|
$PIP_CMD
|
|
|
|
fi
|
2022-10-21 08:35:29 +08:00
|
|
|
|
2023-08-06 22:37:56 +08:00
|
|
|
call_shfmt() {
|
2024-02-25 08:43:28 +08:00
|
|
|
local FLAGS=$1
|
2023-08-06 22:37:56 +08:00
|
|
|
if [ -x "$(command -v shfmt)" ]; then
|
2024-02-25 08:43:28 +08:00
|
|
|
local SHFMT_FILES=$(find . -name "*.sh" -not -path "./.venv/*")
|
2023-08-06 22:37:56 +08:00
|
|
|
# Indents are four spaces, binary ops can start a line, indent switch cases,
|
|
|
|
# and allow spaces following a redirect
|
2024-02-26 07:02:50 +08:00
|
|
|
shfmt ${FLAGS} -i 4 -bn -ci -sr -d ${SHFMT_FILES}
|
2023-08-06 22:37:56 +08:00
|
|
|
else
|
|
|
|
echo "shfmt not installed, skipping"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-03-03 05:56:37 +08:00
|
|
|
if [[ $FIX == 1 ]]; then
|
2022-10-21 08:35:29 +08:00
|
|
|
isort ${LINT_FILES}
|
2024-04-25 19:29:19 +08:00
|
|
|
ruff format ${LINT_FILES}
|
2024-03-03 05:56:37 +08:00
|
|
|
ruff check --fix --output-format=full ${LINT_FILES}
|
2023-08-06 22:37:56 +08:00
|
|
|
call_shfmt -w
|
2022-09-10 04:45:18 +08:00
|
|
|
else
|
2022-10-21 08:35:29 +08:00
|
|
|
isort --check-only --diff ${LINT_FILES}
|
2024-04-25 19:29:19 +08:00
|
|
|
ruff format --check --diff ${LINT_FILES}
|
2023-08-06 22:37:56 +08:00
|
|
|
call_shfmt
|
2024-03-07 01:41:23 +08:00
|
|
|
|
|
|
|
if [[ -z "$GITHUB_ACTIONS" ]]; then
|
|
|
|
RUFF_OUTPUT_FORMAT=full
|
|
|
|
else
|
|
|
|
RUFF_OUTPUT_FORMAT=github
|
|
|
|
fi
|
|
|
|
|
|
|
|
ruff check --output-format="${RUFF_OUTPUT_FORMAT}" ${LINT_FILES}
|
2022-10-23 07:33:00 +08:00
|
|
|
fi
|
2022-10-22 17:15:44 +08:00
|
|
|
|
|
|
|
# Checking minimum python version
|
2024-09-05 19:55:16 +08:00
|
|
|
vermin -vvv --no-tips -t=3.10- --eval-annotations --violations ${LINT_FILES}
|
2022-10-26 08:46:53 +08:00
|
|
|
|
2024-03-22 01:32:18 +08:00
|
|
|
# mypy is run in a separate step on GitHub Actions
|
|
|
|
if [[ -z "$GITHUB_ACTIONS" ]]; then
|
2024-09-01 08:12:56 +08:00
|
|
|
mypy pwndbg gdbinit.py lldbinit.py pwndbg-lldb.py
|
2024-03-22 01:32:18 +08:00
|
|
|
fi
|