Files
typeshed/pre-commit
Sebastian Rittau 4586ed9adc Require black and isort for contributions (#3329)
* Add explanation to CONTRIBUTNG.md
* Add sample pre-commit script
* Check for correctly formatted files in CI

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2020-06-28 15:28:28 -07:00

29 lines
982 B
Bash
Executable File

#!/bin/sh
#
# An example hook script that will run flake8, black, and isort
# prior to committing and will stop the commit if there are any
# warnings. Adjust BIN_DIR to the virtual environment where flake8,
# black, and isort are installed.
#
# To enable this hook, copy this file to ".git/hooks".
BIN_DIR=./.venv/bin
CHANGED_FILES=$(git diff --cached --name-only --diff-filter=AM | grep .pyi || true)
if test -n "${CHANGED_FILES}" -a -d "${BIN_DIR}"; then
${BIN_DIR}/flake8 ${CHANGED_FILES}
${BIN_DIR}/black --check ${CHANGED_FILES}
${BIN_DIR}/isort --check-only ${CHANGED_FILES}
# Replace the last two lines with the following lines
# if you want to reformat changed files automatically
# before committing. Please note that partial commits
# (git add -p) will not work and will commit the whole
# file!
#
# ${BIN_DIR}/black ${CHANGED_FILES} || true
# ${BIN_DIR}/isort -y ${CHANGED_FILES} || true
# git add ${CHANGED_FILES}
fi