-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds function for generating lefthook configuration files
- Loading branch information
Showing
8 changed files
with
155 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.direnv/ | ||
.justfile | ||
.pre-commit-config.yaml | ||
.prettierignore | ||
site/ | ||
lefthook.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ pkgs, lib }: | ||
{ | ||
/* Creates a lefthook.yml file for configuring lefthook. | ||
*/ | ||
mkConfig = import ./mkConfig.nix { inherit pkgs lib; }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ pkgs, lib }: | ||
data: | ||
with pkgs.lib; | ||
let | ||
files = [ ./template.cue ]; | ||
output = "lefthook.yml"; | ||
lefthook = pkgs.lefthook; | ||
|
||
# Add an extra hook for adding required stages whenever the file changes | ||
skip_attrs = [ | ||
"colors" | ||
"extends" | ||
"skip_output" | ||
"source_dir" | ||
"source_dir_local" | ||
]; | ||
stages = builtins.attrNames (builtins.removeAttrs data skip_attrs); | ||
stagesStr = builtins.concatStringsSep " " stages; | ||
shellHookExtra = '' | ||
# Install configured hooks | ||
for stage in ${stagesStr}; do | ||
${lefthook}/bin/lefthook add -a "$stage" | ||
done | ||
''; | ||
|
||
# Generate the module | ||
result = lib.mkTemplate { | ||
inherit data files output shellHookExtra; | ||
}; | ||
in | ||
{ | ||
inherit (result) configFile shellHook; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#Config: { | ||
[string]: #Hook | ||
colors?: bool | *true | ||
extends?: [...string] | ||
skip_output?: [...string] | ||
source_dir?: string | ||
source_dir_local?: string | ||
... | ||
} | ||
|
||
#Hook: { | ||
commands?: [string]: #Command | ||
exclude_tags?: [...string] | ||
parallel?: bool | *false | ||
piped?: bool | *false | ||
scripts?: [string]: #Script | ||
... | ||
} | ||
|
||
#Command: { | ||
exclude?: string | ||
files?: string | ||
glob?: string | ||
root?: string | ||
run: string | ||
skip?: bool | [...string] | ||
tags?: string | ||
... | ||
} | ||
|
||
#Script: { | ||
runner: string | ||
... | ||
} | ||
|
||
{ | ||
#Config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ pkgs, plugins }: | ||
let | ||
output = plugins.lefthook.mkConfig { | ||
commit-msg = { | ||
scripts = { | ||
template_checker = { runner = "bash"; }; | ||
}; | ||
}; | ||
pre-commit = { | ||
commands = { | ||
stylelint = { | ||
tags = "frontend style"; | ||
glob = "*.js"; | ||
run = "yarn stylelint {staged_files}"; | ||
}; | ||
rubocop = { | ||
tags = "backend style"; | ||
glob = "*.rb"; | ||
exclude = "application.rb|routes.rb"; | ||
run = "bundle exec rubocop --force-exclusion {all_files}"; | ||
}; | ||
}; | ||
scripts = { | ||
"good_job.js" = { runner = "node"; }; | ||
}; | ||
}; | ||
}; | ||
|
||
result = pkgs.runCommand "test.lefthook" | ||
{ } | ||
'' | ||
cmp "${./expected.yml}" "${output.configFile}" | ||
touch $out | ||
''; | ||
in | ||
result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
commit-msg: | ||
scripts: | ||
template_checker: | ||
runner: bash | ||
pre-commit: | ||
commands: | ||
rubocop: | ||
exclude: application.rb|routes.rb | ||
glob: '*.rb' | ||
run: bundle exec rubocop --force-exclusion {all_files} | ||
tags: backend style | ||
stylelint: | ||
glob: '*.js' | ||
run: yarn stylelint {staged_files} | ||
tags: frontend style | ||
scripts: | ||
good_job.js: | ||
runner: node |