Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

fix(builtins): add golangci_lint support for monorepos #1557

Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion doc/BUILTINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 6 additions & 4 deletions lua/null-ls/builtins/diagnostics/golangci_lint.lua
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
Expand All @@ -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
Expand Down