Skip to content

Commit

Permalink
pre-commit hook: fail on hlint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Sep 21, 2023
1 parent 039693b commit 1d6cbbd
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions scripts/githooks/haskell-style-lint
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
# ln -s $(git-root)/scripts/githooks/haskell-style-lint $(git rev-parse --git-dir)/hooks/pre-commit
#

for x in $(git diff --staged --name-only --diff-filter=ACM | tr '\n' ' '); do
if [ "${x##*.}" = "hs" ]; then
if grep -qE '^#' "$x"; then
echo "$x contains CPP. Skipping."
else
stylish-haskell -i "$x"
fi
# fail on linting issues
hlint "$x"
hlint_rc="0"

for x in $(git diff --staged --name-only --diff-filter=ACM "*.hs" | tr '\n' ' '); do
if grep -qE '^#' "$x"; then
echo "$x contains CPP. Skipping."
else
stylish-haskell -i "$x"
fi
hlint "$x" || hlint_rc="1"
done

# fail if there are style issues
git --no-pager diff --exit-code
git --no-pager diff --exit-code || exit 1
# if there are no style issue, there could be hlint issues:
exit $hlint_rc

0 comments on commit 1d6cbbd

Please sign in to comment.