Skip to content

Commit ac756a3

Browse files
committed
feat: add priority to hooks.
1 parent d8c02f0 commit ac756a3

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

modules/hook.nix

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ in
135135
default = true;
136136
};
137137

138+
priority = mkOption {
139+
type = types.number;
140+
description = ''
141+
Defines the priority order in which hooks are executed.
142+
Lower the number, the higher the precedence.
143+
'';
144+
default = 0;
145+
};
146+
138147
fail_fast = mkOption {
139148
type = types.bool;
140149
description = ''
@@ -189,7 +198,7 @@ in
189198
config = {
190199
raw =
191200
{
192-
inherit (config) name entry language files types types_or exclude_types pass_filenames fail_fast require_serial stages verbose always_run args;
201+
inherit (config) name entry language files types types_or exclude_types pass_filenames priority fail_fast require_serial stages verbose always_run args;
193202
id = config.name;
194203
exclude = mergeExcludes config.excludes;
195204
};

modules/pre-commit.nix

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,21 @@ let
3030
enabledHooks = filterAttrs (id: value: value.enable) cfg.hooks;
3131
enabledExtraPackages = builtins.concatLists (mapAttrsToList (_: value: value.extraPackages) enabledHooks);
3232
processedHooks =
33-
mapAttrsToList (id: value: value.raw // { inherit id; }) enabledHooks;
33+
let
34+
# Sort the list of hooks by priority (lower number = higher priority)
35+
sortedHooks = builtins.sort
36+
(a: b: a.priority < b.priority)
37+
(mapAttrsToList
38+
(id: value:
39+
value.raw // {
40+
inherit id;
41+
priority = value.raw.priority;
42+
}
43+
)
44+
enabledHooks
45+
);
46+
in
47+
sortedHooks;
3448

3549
configFile =
3650
performAssertions (

0 commit comments

Comments
 (0)