From ac756a3a8208a18e764f87016a04fc8212dcc275 Mon Sep 17 00:00:00 2001 From: Rohit Singh Date: Fri, 13 Dec 2024 09:57:53 +0530 Subject: [PATCH] feat: add priority to hooks. --- modules/hook.nix | 11 ++++++++++- modules/pre-commit.nix | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/modules/hook.nix b/modules/hook.nix index ab58c52b..3fa9f7ff 100644 --- a/modules/hook.nix +++ b/modules/hook.nix @@ -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 = '' @@ -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; }; diff --git a/modules/pre-commit.nix b/modules/pre-commit.nix index d3578d1c..905f9c91 100644 --- a/modules/pre-commit.nix +++ b/modules/pre-commit.nix @@ -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 (