Skip to content

Commit 43983c5

Browse files
authored
Merge pull request #501 from hmajid2301/add-golines
add golines pre-commit hook
2 parents 307718f + 7e36b4c commit 43983c5

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-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 {
@@ -2605,6 +2619,31 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
26052619
# all file names in a single run.
26062620
require_serial = true;
26072621
};
2622+
golines =
2623+
{
2624+
name = "golines";
2625+
description = "A golang formatter that fixes long lines";
2626+
package = tools.golines;
2627+
entry =
2628+
let
2629+
script = pkgs.writeShellScript "precommit-golines" ''
2630+
set -e
2631+
failed=false
2632+
for file in "$@"; do
2633+
# redirect stderr so that violations and summaries are properly interleaved.
2634+
if ! ${hooks.golines.package}/bin/golines ${hooks.golines.settings.flags} -w "$file" 2>&1
2635+
then
2636+
failed=true
2637+
fi
2638+
done
2639+
if [[ $failed == "true" ]]; then
2640+
exit 1
2641+
fi
2642+
'';
2643+
in
2644+
builtins.toString script;
2645+
files = "\\.go$";
2646+
};
26082647
gotest = {
26092648
name = "gotest";
26102649
description = "Run go tests";

nix/tools.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
, go
8585
, go-tools
8686
, golangci-lint
87+
, golines
8788
, revive ? null
8889
, vale
8990
}:
@@ -123,6 +124,7 @@ in
123124
go
124125
go-tools
125126
golangci-lint
127+
golines
126128
gptcommit
127129
hadolint
128130
hindent

0 commit comments

Comments
 (0)