File tree Expand file tree Collapse file tree 3 files changed +59
-24
lines changed Expand file tree Collapse file tree 3 files changed +59
-24
lines changed Original file line number Diff line number Diff line change 2525 '' ;
2626 } ;
2727
28+ id = mkOption {
29+ type = types . str ;
30+ default = name ;
31+ defaultText = "the attribute name the hook submodule is bound to" ;
32+ description =
33+ ''
34+ The unique identifier for the hook.
35+
36+ You do not need to set or modify this value.
37+
38+ The `id` is used to reference a hook when using `pre-commit run <id>`.
39+ It can also be used to reference the hook in other hooks' `before` and `after` fields to define the order in which hooks run.
40+
41+ The `id` is set to the attribute name the hook submodule is bound to in the parent module.
42+ For example, the `id` of following hook would be `my-hook`.
43+
44+ ```nix
45+ {
46+ hooks = {
47+ my-hook = {
48+ enable = true;
49+ entry = "my-hook";
50+ };
51+ }
52+ }
53+ ```
54+ '' ;
55+ } ;
56+
2857 name = mkOption {
2958 type = types . str ;
30- defaultText = lib . literalMD "internal name, same as `id`" ;
3159 default = name ;
60+ defaultText = lib . literalMD "the attribute name the hook submodule is bound to, same as `id`" ;
3261 description =
3362 ''
3463 The name of the hook. Shown during hook execution.
202231 '' ;
203232 default = [ ] ;
204233 } ;
205-
206234 } ;
207235
208236 config = {
209237 raw =
210238 {
211- inherit ( config ) name entry language files types types_or exclude_types pass_filenames fail_fast require_serial stages verbose always_run args before after ;
212- id = config . name ;
239+ inherit ( config ) id name entry language files types types_or exclude_types pass_filenames fail_fast require_serial stages verbose always_run args ;
213240 exclude = mergeExcludes config . excludes ;
214241 } ;
215242 } ;
Original file line number Diff line number Diff line change 19901990 binPath = migrateBinPathToPackage hooks . biome "/bin/biome" ;
19911991 cmdArgs =
19921992 mkCmdArgs [
1993- [ ( hooks . biome . settings . write ) "--apply " ]
1993+ [ ( hooks . biome . settings . write ) "--write " ]
19941994 [ ( hooks . biome . settings . configPath != "" ) "--config-path ${ hooks . biome . settings . configPath } " ]
19951995 ] ;
19961996 in
Original file line number Diff line number Diff line change 99 mapAttrsToList
1010 mkOption
1111 types
12- removeAttrs
1312 remove
1413 ;
1514
3433 let
3534 sortedHooks = lib . toposort
3635 ( a : b : builtins . elem b . id a . before || builtins . elem a . id b . after )
37- ( mapAttrsToList
38- ( id : value :
39- value . raw // {
40- inherit id ;
41- before = value . raw . before ;
42- after = value . raw . after ;
43- }
44- )
45- enabledHooks
46- ) ;
47- cleanedHooks = builtins . map (
48- hook :
49- removeAttrs hook [
50- "before"
51- "after"
52- ]
53- ) sortedHooks . result ;
36+ ( builtins . attrValues enabledHooks ) ;
5437 in
55- cleanedHooks ;
38+ if sortedHooks ? result then
39+ builtins . map ( value : value . raw ) sortedHooks . result
40+ else
41+ let
42+ getIds = builtins . map ( value : value . id ) ;
43+
44+ prettyPrintCycle = opts : cycle :
45+ lib . pipe cycle [
46+ ( builtins . map ( hook :
47+ lib . nameValuePair hook . id { before = hook . before ; after = hook . after ; }
48+ ) )
49+ lib . listToAttrs
50+ ( lib . generators . toPretty opts )
51+ ] ;
52+ in
53+ throw ''
54+ The hooks can't be sorted because of a cycle in the dependency graph:
55+
56+ ${ concatStringsSep " -> " ( getIds sortedHooks . cycle ) }
57+
58+ which leads to a loop back to: ${ concatStringsSep ", " ( getIds sortedHooks . loops ) }
59+
60+ Try removing the conflicting hook ids from the `before` and `after` attributes of these hooks:
61+
62+ ${ prettyPrintCycle { indent = " " ; } sortedHooks . cycle }
63+ '' ;
5664
5765 configFile =
5866 performAssertions (
You can’t perform that action at this time.
0 commit comments