Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add golines pre-commit hook #501

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 {
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