From 198986b3fb13c5c1f89b0e47103b9014a3147b73 Mon Sep 17 00:00:00 2001 From: RoastedCheese Date: Tue, 19 May 2026 13:57:53 +0200 Subject: [PATCH] languages/go: fix scope of golangci-lint --- docs/manual/release-notes/rl-0.9.md | 4 ++++ modules/plugins/languages/go.nix | 36 +++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index a1c95e9f..f614b4ec 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -551,4 +551,8 @@ https://github.com/gorbit99/codewindow.nvim - Allow `vim.treesitter.context.setupOpts.max_lines` to also be given as a string in order to allow percentage values like `"20%"` +[RoastedCheese](https://github.com/roastedcheese): + +- Fix `golangci-lint` to lint at the package level. + diff --git a/modules/plugins/languages/go.nix b/modules/plugins/languages/go.nix index 1e644bac..14f30314 100644 --- a/modules/plugins/languages/go.nix +++ b/modules/plugins/languages/go.nix @@ -67,7 +67,21 @@ "--output.junit-xml.path=" "--output.teamcity.path=" "--output.sarif.path=" + (mkLuaInline '' + -- Run on current file only if go.mod is missing + function() + local fnmod = ":p"; + local cmd = {"${getExe pkgs.go}", "env", "GOMOD"}; + local ok, gomod = pcall(vim.fn.system, cmd); + gomod = gomod:gsub("%s+", "") + if ok and gomod ~= "" and gomod ~= "/dev/null" then + fnmod = ":h"; + end + return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), fnmod) + end + '') ]; + append_fname = false; parser = mkLuaInline '' function(output, bufnr) local SOURCE = "golangci-lint"; @@ -111,15 +125,19 @@ local normalized = issue.Severity:lower() sev = severity_map[normalized] or vim.diagnostic.severity.ERROR end - table.insert(diagnostics, { - bufnr = bufnr, - lnum = issue.Pos.Line - 1, - col = issue.Pos.Column - 1, - message = issue.Text, - code = issue.FromLinter, - severity = sev, - source = SOURCE, - }) + + local buffer = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":p") + if vim.fs.normalize(buffer) == vim.fs.normalize(issue.Pos.Filename) then + table.insert(diagnostics, { + bufnr = bufnr, + lnum = issue.Pos.Line - 1, + col = issue.Pos.Column - 1, + message = issue.Text, + code = issue.FromLinter, + severity = sev, + source = SOURCE, + }) + end end return diagnostics end