Skip to content

Commit 1a1c7c6

Browse files
committed
add golines pre-commit hook
1 parent 1211305 commit 1a1c7c6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

modules/hooks.nix

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,20 @@ in
565565
};
566566
};
567567
};
568+
golines = mkOption {
569+
description = "golines hook";
570+
type = types.submodule {
571+
imports = [ hookModule ];
572+
options.settings = {
573+
flags = mkOption {
574+
type = types.str;
575+
description = "Flags passed to golines. See all available [here](https://github.com/segmentio/golines?tab=readme-ov-file#options)";
576+
default = "";
577+
example = "-m 120";
578+
};
579+
};
580+
};
581+
};
568582
headache = mkOption {
569583
description = "headache hook";
570584
type = types.submodule {
@@ -2487,6 +2501,31 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
24872501
# all file names in a single run.
24882502
require_serial = true;
24892503
};
2504+
golines =
2505+
{
2506+
name = "golines";
2507+
description = "A golang formatter that fixes long lines";
2508+
package = tools.golines;
2509+
entry =
2510+
let
2511+
script = pkgs.writeShellScript "precommit-golines" ''
2512+
set -e
2513+
failed=false
2514+
for file in "$@"; do
2515+
# redirect stderr so that violations and summaries are properly interleaved.
2516+
if ! ${hooks.golines.package}/bin/golines ${hooks.golines.settings.flags} -w "$file" 2>&1
2517+
then
2518+
failed=true
2519+
fi
2520+
done
2521+
if [[ $failed == "true" ]]; then
2522+
exit 1
2523+
fi
2524+
'';
2525+
in
2526+
builtins.toString script;
2527+
files = "\\.go$";
2528+
};
24902529
gotest = {
24912530
name = "gotest";
24922531
description = "Run go tests";

0 commit comments

Comments
 (0)