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

fix(builtins): set correct golangci_lint cwd #1206

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
fix(builtins): set correct golangci_lint cwd
marcelbeumer committed Dec 28, 2022
commit 6f81824674318497e7306be505d986bb624aac78
12 changes: 8 additions & 4 deletions lua/null-ls/builtins/diagnostics/golangci_lint.lua
Original file line number Diff line number Diff line change
@@ -17,13 +17,16 @@ return h.make_builtin({
to_stdin = true,
from_stderr = false,
ignore_stderr = true,
cwd = function(params)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a huge deal, since this linter runs (relatively) infrequently, but if we don't expect this result to change, I think we want to cache this to avoid repeated lookups. You may also want to consider using the root_pattern utility. This builtin has an example of both.

local patterns = { "go.mod", "go.work", ".git" }
local opts = { upward = true, path = params.bufname }
local cwd = vim.fs.dirname(vim.fs.find(patterns, opts)[1]) or vim.fn.getcwd()
return vim.loop.fs_realpath(cwd)
end,
args = {
"run",
"--fix=false",
"--fast",
"--out-format=json",
"--path-prefix",
"$ROOT",
},
format = "json",
check_exit_code = function(code)
@@ -38,7 +41,8 @@ return h.make_builtin({
local issues = params.output["Issues"]
if type(issues) == "table" then
for _, d in ipairs(issues) do
if d.Pos.Filename == params.bufname then
local fname = params.cwd .. "/" .. d.Pos.Filename
Copy link
Contributor Author

@marcelbeumer marcelbeumer Oct 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing this here instead of using --path-prefix so it's easier for consumers to modify the args with .with({ args (or is there a way to retrieve (resolved) .cwd from .with(?)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this not working, or did the other change make this one necessary? Either way I think this is fine, though we'll want to use the join_path utility (example) to guarantee consistency.

if fname == params.bufname then
table.insert(diags, {
source = string.format("golangci-lint:%s", d.FromLinter),
row = d.Pos.Line,