Skip to content

Commit

Permalink
feat: add priority to hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsrohitsingh682 committed Dec 13, 2024
1 parent d8c02f0 commit ac756a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 10 additions & 1 deletion modules/hook.nix
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ in
default = true;
};

priority = mkOption {
type = types.number;
description = ''
Defines the priority order in which hooks are executed.
Lower the number, the higher the precedence.
'';
default = 0;
};

fail_fast = mkOption {
type = types.bool;
description = ''
Expand Down Expand Up @@ -189,7 +198,7 @@ in
config = {
raw =
{
inherit (config) name entry language files types types_or exclude_types pass_filenames fail_fast require_serial stages verbose always_run args;
inherit (config) name entry language files types types_or exclude_types pass_filenames priority fail_fast require_serial stages verbose always_run args;
id = config.name;
exclude = mergeExcludes config.excludes;
};
Expand Down
16 changes: 15 additions & 1 deletion modules/pre-commit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ let
enabledHooks = filterAttrs (id: value: value.enable) cfg.hooks;
enabledExtraPackages = builtins.concatLists (mapAttrsToList (_: value: value.extraPackages) enabledHooks);
processedHooks =
mapAttrsToList (id: value: value.raw // { inherit id; }) enabledHooks;
let
# Sort the list of hooks by priority (lower number = higher priority)
sortedHooks = builtins.sort
(a: b: a.priority < b.priority)
(mapAttrsToList
(id: value:
value.raw // {
inherit id;
priority = value.raw.priority;
}
)
enabledHooks
);
in
sortedHooks;

configFile =
performAssertions (
Expand Down

0 comments on commit ac756a3

Please sign in to comment.