pwndbg/lint.sh

77 lines
1.6 KiB
Bash
Raw Normal View History

2022-09-05 19:18:40 +08:00
#!/bin/bash
set -o errexit
help_and_exit() {
echo "Usage: ./lint.sh [-f|--filter]"
echo " -f, --filter format code instead of just checking the format"
exit 1
}
if [[ $# -gt 1 ]]; then
help_and_exit
fi
FORMAT=0
while [[ $# -gt 0 ]]; do
case $1 in
-f | --format)
FORMAT=1
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
source "${PWNDBG_VENV_PATH}/bin/activate"
2024-02-26 07:02:50 +08:00
set -o xtrace
LINT_FILES="pwndbg tests *.py"
2023-08-06 22:37:56 +08:00
LINT_TOOLS="isort black ruff vermin mypy"
if ! type ${LINT_TOOLS} &> /dev/null; then
PIP_CMD="pip install -Ur dev-requirements.txt"
echo "Missing one of the following tools: ${LINT_TOOLS}"
echo "Running '${PIP_CMD}'"
$PIP_CMD
fi
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
}
if [[ $FORMAT == 1 ]]; then
isort ${LINT_FILES}
black ${LINT_FILES}
2023-08-06 22:37:56 +08:00
call_shfmt -w
else
isort --check-only --diff ${LINT_FILES}
black --check --diff ${LINT_FILES}
2023-08-06 22:37:56 +08:00
call_shfmt
fi
2022-10-22 17:15:44 +08:00
# Checking minimum python version
vermin -vvv --no-tips -t=3.8- --violations ./pwndbg/
ruff check --output-format=full ${LINT_FILES}
2023-08-06 22:37:56 +08:00
mypy pwndbg