Follow instructions from readme: https://github.com/cachix/pre-commit-hooks.nix/blob/61a3511668891c68ebd19d40122150b98dc2fe3b/README.md?plain=1#L31-L73
Now inspect .pre-commit-config.yaml:
Details
# DO NOT MODIFY
# This file was generated by pre-commit-hooks.nix
{
"default_stages": [
"commit"
],
"repos": [
{
"hooks": [
{
"entry": "/nix/store/yyc8pmfy43nl2hwfb3n16rcd866nqki8-elm-format-0.8.5/bin/elm-format --yes --elm-version=0.19",
"exclude": "^$",
"files": "\\.elm$",
"id": "elm-format",
"language": "system",
"name": "elm-format",
"pass_filenames": true,
"stages": [
"commit"
],
"types": [
"file"
],
"types_or": []
},
{
"entry": "/nix/store/gvp4jil2i6r4n7kvx4sh4d7vhp5v433j-ormolu-0.3.1.0-bin/bin/ormolu --mode inplace '--ghc-opt' '-Xlhs' '--ghc-opt' '-Xhs' ",
"exclude": "^$",
"files": "\\.l?hs(-boot)?$",
"id": "ormolu",
"language": "system",
"name": "ormolu",
"pass_filenames": true,
"stages": [
"commit"
],
"types": [
"file"
],
"types_or": []
},
{
"entry": "/nix/store/25i9mjmk2a0pq19jgiscn3wfc539ya3a-shellcheck-0.8.0-bin/bin/shellcheck",
"exclude": "^$",
"files": "",
"id": "shellcheck",
"language": "system",
"name": "shellcheck",
"pass_filenames": true,
"stages": [
"commit"
],
"types": [
"shell"
],
"types_or": [
"sh",
"ash",
"bash",
"bats",
"dash",
"ksh"
]
}
],
"repo": "local"
}
]
}
You'll see the order of hooks is:
- elm-format
- ormolu
- shellcheck
Now, change the order of hooks in default.nix. Set them like:
hooks = {
shellcheck.enable = true;
ormolu.enable = true;
elm-format.enable = true;
};
Again, enter nix-shell and inspect .pre-commit-config.yaml. You'll see that the hooks are in the same order as the 1st time. The file is in fact the same.
This is not a big problem in this case, but in other cases, order matter.
For example, if you're writing python and want to enable autoflake and flake8, you will most likely want autoflake to run before flake8, so flake8 doesn't catch the errors that autoflake already fixed.
In specific cases like this one, we could still provide a sane default order. But there are custom hooks, and we can't predict in which order they should be executed.
So, this project needs IMHO a way to specify hook order, just like normal pre-commit does.
Follow instructions from readme: https://github.com/cachix/pre-commit-hooks.nix/blob/61a3511668891c68ebd19d40122150b98dc2fe3b/README.md?plain=1#L31-L73
Now inspect
.pre-commit-config.yaml:Details
You'll see the order of hooks is:
Now, change the order of hooks in
default.nix. Set them like:Again, enter
nix-shelland inspect.pre-commit-config.yaml. You'll see that the hooks are in the same order as the 1st time. The file is in fact the same.This is not a big problem in this case, but in other cases, order matter.
For example, if you're writing python and want to enable
autoflakeandflake8, you will most likely wantautoflaketo run beforeflake8, soflake8doesn't catch the errors thatautoflakealready fixed.In specific cases like this one, we could still provide a sane default order. But there are custom hooks, and we can't predict in which order they should be executed.
So, this project needs IMHO a way to specify hook order, just like normal pre-commit does.