Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,20 @@ in
};
};
};
golines = mkOption {
description = "golines hook";
type = types.submodule {
imports = [ hookModule ];
options.settings = {
flags = mkOption {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, all hooks accept an args option that does this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh good to know for the next one thanks

type = types.str;
description = "Flags passed to golines. See all available [here](https://github.com/segmentio/golines?tab=readme-ov-file#options)";
default = "";
example = "-m 120";
};
};
};
};
headache = mkOption {
description = "headache hook";
type = types.submodule {
Expand Down Expand Up @@ -2487,6 +2501,31 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
# all file names in a single run.
require_serial = true;
};
golines =
{
name = "golines";
description = "A golang formatter that fixes long lines";
package = tools.golines;
entry =
let
script = pkgs.writeShellScript "precommit-golines" ''
set -e
failed=false
for file in "$@"; do
# redirect stderr so that violations and summaries are properly interleaved.
if ! ${hooks.golines.package}/bin/golines ${hooks.golines.settings.flags} -w "$file" 2>&1
then
failed=true
fi
done
if [[ $failed == "true" ]]; then
exit 1
fi
'';
in
builtins.toString script;
files = "\\.go$";
};
gotest = {
name = "gotest";
description = "Run go tests";
Expand Down
2 changes: 2 additions & 0 deletions nix/tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
, go
, go-tools
, golangci-lint
, golines
, revive ? null
, vale
}:
Expand Down Expand Up @@ -123,6 +124,7 @@ in
go
go-tools
golangci-lint
golines
gptcommit
hadolint
hindent
Expand Down