From 0067c7ce77ef4e8d671237f938c48716f9810df8 Mon Sep 17 00:00:00 2001 From: Snowflake Date: Sat, 25 Nov 2023 10:55:23 +0800 Subject: [PATCH] Add golangci-lint --- README.md | 1 + modules/hooks.nix | 19 +++++++++++++++++++ nix/tools.nix | 2 ++ 3 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 8310dc98..abd8f55b 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,7 @@ use nix - gofmt: Runs `go fmt` - gotest: Runs `go test` +- [golangci-lint](https://golangci-lint.run/) - [govet](https://pkg.go.dev/cmd/vet) - [revive](https://github.com/mgechev/revive) - [staticcheck](https://github.com/dominikh/go-tools) diff --git a/modules/hooks.nix b/modules/hooks.nix index e7bba8ad..dc5977e6 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -2208,5 +2208,24 @@ in description = "Runs the git-annex hook for large file support"; entry = "${tools.git-annex}/bin/git-annex pre-commit"; }; + + golangci-lint = { + name = "golangci-lint"; + description = "Fast linters runner for Go."; + entry = + let + script = pkgs.writeShellScript "precommit-golangci-lint" '' + set -e + for dir in $(echo "$@" | xargs -n1 dirname | sort -u); do + ${tools.golangci-lint}/bin/golangci-lint run ./"$dir" + done + ''; + in + builtins.toString script; + files = "\\.go$"; + # to avoid multiple invocations of the same directory input, provide + # all file names in a single run. + require_serial = true; + }; }; } diff --git a/nix/tools.nix b/nix/tools.nix index 212ce185..aa49d5ea 100644 --- a/nix/tools.nix +++ b/nix/tools.nix @@ -67,6 +67,7 @@ , writeText , go , go-tools +, golangci-lint , revive ? null }: @@ -98,6 +99,7 @@ in git-annex go go-tools + golangci-lint gptcommit hadolint hindent