diff --git a/doc/BUILTINS.md b/doc/BUILTINS.md index d744558de..1947d8e3a 100644 --- a/doc/BUILTINS.md +++ b/doc/BUILTINS.md @@ -1073,7 +1073,7 @@ local sources = { null_ls.builtins.diagnostics.golangci_lint } - Filetypes: `{ "go" }` - Method: `diagnostics_on_save` - Command: `golangci-lint` -- Args: `{ "run", "--fix=false", "--out-format=json", "--path-prefix", "$ROOT" }` +- Args: `{ "run", "--fix=false", "--out-format=json" }` ### [gospel](https://github.com/kortschak/gospel) diff --git a/lua/null-ls/builtins/diagnostics/golangci_lint.lua b/lua/null-ls/builtins/diagnostics/golangci_lint.lua index e443b2206..eaa812858 100644 --- a/lua/null-ls/builtins/diagnostics/golangci_lint.lua +++ b/lua/null-ls/builtins/diagnostics/golangci_lint.lua @@ -1,6 +1,7 @@ local h = require("null-ls.helpers") local methods = require("null-ls.methods") local log = require("null-ls.logger") +local u = require("null-ls.utils") local DIAGNOSTICS_ON_SAVE = methods.internal.DIAGNOSTICS_ON_SAVE @@ -18,12 +19,13 @@ return h.make_builtin({ from_stderr = false, ignore_stderr = true, multiple_files = true, + cwd = h.cache.by_bufnr(function(params) + return u.root_pattern("go.mod")(params.bufname) + end), args = { "run", "--fix=false", "--out-format=json", - "--path-prefix", - "$ROOT", }, format = "json", check_exit_code = function(code) @@ -39,12 +41,12 @@ return h.make_builtin({ if type(issues) == "table" then for _, d in ipairs(issues) do table.insert(diags, { - source = string.format("golangci-lint:%s", d.FromLinter), + source = string.format("golangci-lint: %s", d.FromLinter), row = d.Pos.Line, col = d.Pos.Column, message = d.Text, severity = h.diagnostics.severities["warning"], - filename = d.Pos.Filename, + filename = u.path.join(params.cwd, d.Pos.Filename), }) end end