Created
June 11, 2022 21:46
-
-
Save adophilus/cd6c5beeebc37e9233dd666b1bba652d to your computer and use it in GitHub Desktop.
A shell script storing the commands to run before a git commit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/data/data/com.termux/files/usr/bin/bash | |
# NOTE: this file script should be placed at .git/hooks/pre-commit | |
# for linux users, this script should be made executable using the | |
# command: | |
# chmod +x .git/hooks/pre-commit | |
STAGED_FILES="$(git diff --name-only --staged)" | |
FILES_TO_LINT="" | |
EXCLUDED_FILES=".gitignore yarn.lock" | |
# compile the files to be linted | |
for _file in $STAGED_FILES; | |
do | |
if [[ -f $_file ]]; | |
then | |
FILES_TO_LINT="$FILES_TO_LINT $_file" | |
fi | |
done | |
# remove excluded files from the list of files to lint | |
for _file in $EXCLUDED_FILES; | |
do | |
FILES_TO_LINT=$(echo $FILES_TO_LINT | sed --expression "s/${_file}//") | |
done | |
# format the files | |
# NOTE: USE THE OPTION '--write' WITH CAUTION! https://prettier.io/docs/en/cli.html | |
yarn format --write $FILES_TO_LINT | |
# lint the files | |
yarn lint --fix $FILES_TO_LINT | |
# stage the linted files | |
echo $FILES_TO_LINT | xargs -l git add |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment