Last active
January 9, 2026 12:23
-
-
Save abdivasiyev/eec72445c494f5e4712b627baf5506ce to your computer and use it in GitHub Desktop.
Nilaway enabled golangci-lint for pre-commit hooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 39a0771134cf2ebc355f94d1a402c9f061b5ee66 Mon Sep 17 00:00:00 2001 | |
| From: Asliddin Abdivasiyev <asliddin.abdivasiyev@gmail.com> | |
| Date: Fri, 9 Jan 2026 17:04:59 +0500 | |
| Subject: [PATCH] feat: Add nilaway plugin | |
| --- | |
| cmd/golangci-lint/plugins.go | 2 +- | |
| go.mod | 2 ++ | |
| go.sum | 4 ++++ | |
| 3 files changed, 7 insertions(+), 1 deletion(-) | |
| diff --git a/cmd/golangci-lint/plugins.go b/cmd/golangci-lint/plugins.go | |
| index 541ff762..aa16ef61 100644 | |
| --- a/cmd/golangci-lint/plugins.go | |
| +++ b/cmd/golangci-lint/plugins.go | |
| @@ -1,3 +1,3 @@ | |
| package main | |
| -// This file is used to declare module plugins. | |
| +import _ "go.uber.org/nilaway/cmd/gclplugin" | |
| diff --git a/go.mod b/go.mod | |
| index a9e81cbd..8713aee0 100644 | |
| --- a/go.mod | |
| +++ b/go.mod | |
| @@ -139,6 +139,7 @@ require ( | |
| go.augendre.info/arangolint v0.3.1 | |
| go.augendre.info/fatcontext v0.9.0 | |
| go.uber.org/automaxprocs v1.6.0 | |
| + go.uber.org/nilaway v0.0.0-20251208195206-89df5f7e6199 | |
| go.yaml.in/yaml/v3 v3.0.4 | |
| golang.org/x/mod v0.31.0 | |
| golang.org/x/sync v0.19.0 | |
| @@ -187,6 +188,7 @@ require ( | |
| github.com/hashicorp/hcl v1.0.0 // indirect | |
| github.com/hexops/gotextdiff v1.0.3 // indirect | |
| github.com/inconshreveable/mousetrap v1.1.0 // indirect | |
| + github.com/klauspost/compress v1.18.0 // indirect | |
| github.com/ldez/structtags v0.6.1 // indirect | |
| github.com/lucasb-eyer/go-colorful v1.2.0 // indirect | |
| github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect | |
| diff --git a/go.sum b/go.sum | |
| index 549c9316..00026767 100644 | |
| --- a/go.sum | |
| +++ b/go.sum | |
| @@ -370,6 +370,8 @@ github.com/kisielk/errcheck v1.9.0/go.mod h1:kQxWMMVZgIkDq7U8xtG/n2juOjbLgZtedi0 | |
| github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= | |
| github.com/kkHAIKE/contextcheck v1.1.6 h1:7HIyRcnyzxL9Lz06NGhiKvenXq7Zw6Q0UQu/ttjfJCE= | |
| github.com/kkHAIKE/contextcheck v1.1.6/go.mod h1:3dDbMRNBFaq8HFXWC1JyvDSPm43CmE6IuHam8Wr0rkg= | |
| +github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= | |
| +github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= | |
| github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= | |
| github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= | |
| github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= | |
| @@ -651,6 +653,8 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= | |
| go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= | |
| go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= | |
| go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= | |
| +go.uber.org/nilaway v0.0.0-20251208195206-89df5f7e6199 h1:g3BCLExlgKmPrOYZxhjqyNz4ySS1X3ULGzhacN0XNnk= | |
| +go.uber.org/nilaway v0.0.0-20251208195206-89df5f7e6199/go.mod h1:pbGMVkhssd5Ee+eoqfgEk9mzoJoKZAhnTbl1QNcYDi0= | |
| go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= | |
| go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= | |
| go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= | |
| -- | |
| 2.49.0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| description = "some service"; | |
| nixConfig = { | |
| allow-import-from-derivation = true; | |
| }; | |
| inputs = { | |
| nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | |
| flake-utils.url = "github:numtide/flake-utils"; | |
| # Git hooks | |
| pre-commit-hooks = { | |
| url = "github:cachix/git-hooks.nix"; | |
| inputs.nixpkgs.follows = "nixpkgs"; | |
| }; | |
| }; | |
| outputs = { | |
| self, | |
| nixpkgs, | |
| flake-utils, | |
| pre-commit-hooks, | |
| ... | |
| }: | |
| flake-utils.lib.eachDefaultSystem ( | |
| system: let | |
| inherit (self.checks.${system}) pre-commit-check; | |
| # pkgs = import nixpkgs {localSystem = {inherit system;};}; | |
| pkgs = nixpkgs.legacyPackages.${system}; | |
| # build golangci-lint with custom linters | |
| golangci-lint = | |
| pkgs.golangci-lint.overrideAttrs | |
| (oldAttrs: rec { | |
| version = "2.8.0"; | |
| src = pkgs.fetchFromGitHub { | |
| owner = "golangci"; | |
| repo = "golangci-lint"; | |
| rev = "v${version}"; | |
| sha256 = "sha256-w6MAOirj8rPHYbKrW4gJeemXCS64fNtteV6IioqIQTQ="; | |
| }; | |
| vendorHash = "sha256-a6tGWnLeqwyLirqpn73v7XXu39cRkXDibDTncf7trWc="; | |
| patches = | |
| oldAttrs.patches or [] | |
| ++ [ | |
| # nilaway plugin patch | |
| (pkgs.fetchurl | |
| { | |
| url = "https://gist.githubusercontent.com/abdivasiyev/eec72445c494f5e4712b627baf5506ce/raw/37d88eb2159f58ee0a4aebf9491e210c8adf959f/0001-feat-Add-nilaway-plugin.patch"; | |
| sha256 = "sha256-G2w/nSuS4h0mYUvMh03vvfPrER6NZNI4jb3F5ZqfbAM="; | |
| }) | |
| ]; | |
| }); | |
| in { | |
| # Tests and suites for this repo | |
| checks = { | |
| pre-commit-check = pre-commit-hooks.lib.${system}.run { | |
| src = ./.; | |
| hooks = { | |
| # golangci-lint.enable = true; | |
| custom-golangci-lint = { | |
| enable = true; | |
| name = "custom-golangci-lint"; | |
| entry = "${golangci-lint}/bin/golangci-lint"; | |
| args = ["./..."]; | |
| files = "\\.go$"; | |
| }; | |
| gotest.enable = true; | |
| go-generate = { | |
| enable = true; | |
| entry = "go"; | |
| args = ["generate" "./..."]; | |
| pass_filenames = false; | |
| files = "\\.go$"; | |
| }; | |
| }; | |
| }; | |
| }; | |
| devShells.default = pkgs.callPackage ./shell.nix {inherit pkgs golangci-lint pre-commit-hooks pre-commit-check;}; | |
| } | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| pkgs ? let | |
| lock = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.nixpkgs.locked; | |
| nixpkgs = fetchTarball { | |
| url = "https://github.com/nixos/nixpkgs/archive/${lock.rev}.tar.gz"; | |
| sha256 = lock.narHash; | |
| }; | |
| in | |
| import nixpkgs {overlays = [];}, | |
| pre-commit-check, | |
| golangci-lint, | |
| ... | |
| }: | |
| pkgs.stdenv.mkDerivation { | |
| name = "some-service-dev-shell"; | |
| # Build time dependencies | |
| nativeBuildInputs = with pkgs; [ | |
| go | |
| gopls | |
| go-tools | |
| golangci-lint | |
| go-swag | |
| delve | |
| sqlc | |
| just | |
| ]; | |
| # Runtime dependencies | |
| buildInputs = [ | |
| pre-commit-check.enabledPackages | |
| ]; | |
| # Things to run before entering devShell | |
| shellHook = '' | |
| export DOCKER_HOST=unix://$HOME/.colima/docker.sock | |
| ${pre-commit-check.shellHook} | |
| ''; | |
| # Environmental variables | |
| NIX_CONFIG = "extra-experimental-features = nix-command flakes"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment