Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #235
Following #235, here is a PR that improves and fixes the
hpack
hook.Changes
...to the
files
patternFirst, we update the
files
pattern to match*.cabal
andpackage.yaml
files everywhere in the repository and not at the root. Thefiles
pattern's components change in the following way:\\.l?hs(-boot)?$
, remains the same. To be honest, I do not understand why this part is useful or necessary. But I did not take the liberty to remove it.^[^/]+\\.cabal$
, changes to\\.cabal$
. This makes it match any*.cabal
file in the repository, while the previous version matched only*.cabal
files at top-level.^package\\.yaml$
, changes to(^|/)package\\.yaml$
. Once again, this makes it match anypackage.yaml
file in the repository while the previous version matched them only at top-level.The
files
pattern matches on the files's paths and not just the names. I did not find any direct reference to that in the documentation of pre-commit. However, its section “Filtering files with types” mentions the following examples:...to the
hpack-dir
scriptSecond, we rewrite the
hpack-dir
script to achieve two things:We replace the call to
hpack
by a call to${hpack}/bin/hpack
. This ensures that the script works also whenhpack
is not present on the machine. This also increases reliability by giving better control tohpack
's version being used in the hook.The previous version also failed silently in case of errors of
hpack
(or error caused by the absence ofhpack
). We suggest a replacement based onset -e
andfind | while
. This design choice is heavily documented in the script itself.Experiments
I have introduced this “fixed” version of the hook in two of Tweag's projects: tweag/pirouette#177 and tweag/cooked-validators#226. I ran some tests locally by hand on both those projects, and also in CI; all have proven successful. The first project has its
package.yaml
and*.cabal
project at top-level and the second within sub-directories.