1.0 KiB
Executable File
1.0 KiB
Executable File
| title | date | tags | ||
|---|---|---|---|---|
| Git tips - lint + test pre-commit hook | 2020-01-01T21:00:39Z |
|
A nice last minute sanity check I use is a pre-commit hook that auto runs test and lint commands from a makefile or
package.json if they're found:
#!/usr/bin/env bash
if [ -f "$PWD/makefile" ] && [ ! -z "$(cat $PWD/makefile | grep '^lint:')" ]; then
echo "running make lint"
make lint
elif [ -f "$PWD/package.json" ] && [ ! -z "$(cat $PWD/package.json | grep "^\"lint\":")" ]; then
echo "running npm run lint"
npm run lint
fi
if [ -f "$PWD/makefile" ] && [ ! -z "$(cat $PWD/makefile | grep '^test:')" ]; then
echo "running make test"
make test
elif [ -f "$PWD/package.json" ] && [ ! -z "$(cat $PWD/package.json | grep "^\"test\":")" ]; then
echo "running npm run test"
npm run test
fi
If the test or lint command fails then the git commit command fails. If I absolutely need to commit something in spite
of the lint/test results I can do git commit --no-verify to skip the pre-commit hook.