Skip to content

Hook order ignored #250

Closed
Closed
@yajo

Description

@yajo

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:

# 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions