Skip to content

Commit

Permalink
add pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
AlaraBread committed Nov 24, 2024
1 parent 4e02639 commit 2ba0233
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,11 @@ To run the same checks that run in ci on your local, you can run
```sh
deno run check
```

## Pre Commit Hook

If you want a pre commit hook that checks file naming, checks formatting, lints, and runs tests, there is a script in `hooks/pre-commit`. To install it, copy `hooks/pre-commit` to `.git/hooks`.

```sh
cp hooks/pre-commit .git/hooks
```
39 changes: 39 additions & 0 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

cd "$(dirname "$0")"
cd ../..
git ls-files | xargs --delimiter="\n" -L 1 basename >dirs.tmp
grep --invert-match --line-regexp --perl-regexp "([a-z\(\)\[\]\.\_\-]*)|([A-Z_]*\.md)" dirs.tmp
if [ $? == 0 ]; then
echo "invalid file name(s)"
exit 1
fi
rm dirs.tmp

cd backend
deno fmt
if [ $? != 0 ]; then
exit 1
fi
deno lint
if [ $? != 0 ]; then
exit 1
fi
deno test
if [ $? != 0 ]; then
exit 1
fi

cd ../frontend
npm run format
if [ $? != 0 ]; then
exit 1
fi
npm run lint
if [ $? != 0 ]; then
exit 1
fi
npm run test:ci
if [ $? != 0 ]; then
exit 1
fi

0 comments on commit 2ba0233

Please sign in to comment.