From 564c7e6af04fd4057a1ca54a2eb346a177cea6a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 20 Sep 2023 15:07:19 +0200 Subject: [PATCH 1/2] cardano-cli: pre-commit: simplify *.hs handling --- scripts/githooks/haskell-style-lint | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/scripts/githooks/haskell-style-lint b/scripts/githooks/haskell-style-lint index 1fd1e1c9f1..79e80ad5c1 100755 --- a/scripts/githooks/haskell-style-lint +++ b/scripts/githooks/haskell-style-lint @@ -7,16 +7,14 @@ # 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" +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 + # fail on linting issues + hlint "$x" done # fail if there are style issues From 1fbafcca32ce9bd5dff449a65f304909f96b2cdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 20 Sep 2023 15:07:48 +0200 Subject: [PATCH 2/2] cardano-cli: pre-commit: fail on hlint errors --- scripts/githooks/haskell-style-lint | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/githooks/haskell-style-lint b/scripts/githooks/haskell-style-lint index 79e80ad5c1..fd52ede1fd 100755 --- a/scripts/githooks/haskell-style-lint +++ b/scripts/githooks/haskell-style-lint @@ -7,15 +7,18 @@ # ln -s $(git-root)/scripts/githooks/haskell-style-lint $(git rev-parse --git-dir)/hooks/pre-commit # +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 - # fail on linting issues - hlint "$x" + 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