-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hook order ignored #250
Comments
Attribute sets are always ordered lexicographically, as a way to simplify language semantics, but I can see that it's a little annoying here. pre-commit-hooks.nix can solve this by adding priority numbers to the Alternatively, it might be possible to add a new type to the module system that makes it slightly more convenient than that, but this would have to be designed with care so that values can be merged from multiple modules without relying on an implicit ordering of those modules, which is a property that integrations such as devenv and flake-parts rely on.
It'd be really nice if a default ordering could be specified declaratively to encode this knowledge so that it just does the right thing. We have a couple of instances in NixOS where we let users declare partial orderings using |
Or maybe this could accept both an attrset or a list of attrsets. Lists are ordered, so if we really care about ordering, we can use the latter form. Example: hooks = [
# Sorted
{autoflake.enable = true;}
{flake8.enable = true;}
# Unsorted
{
shellcheck.enable = true;
ormolu.enable = true;
elm-format.enable = true;
}
] |
+1 If the user has both |
Did anyone managed to solve it? |
No solution yet AFAIK. I guess it should be relatively easy to add support to a |
Perhaps we could eventually use something like |
How would that fix this? |
I suppose you could then have a This doesn't depend on |
I was just wondering what a list-based config for hooks would look like. That would solve the issue of hook order and provide an easy way to repeatedly specify hooks with different options.
Using |
Now I have to ask! Why not? |
Treefmt seems to have it better designed, with a priority field. Maybe we
can imitate it.
https://treefmt.com/latest/getting-started/configure/?h=priority
|
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
:You'll see the order of hooks is:
Now, change the order of hooks in
default.nix
. Set them like: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
andflake8
, you will most likely wantautoflake
to run beforeflake8
, soflake8
doesn't catch the errors thatautoflake
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.
The text was updated successfully, but these errors were encountered: