Skip to content

fix: Error code 5 with golangci-lint v2 #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
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
21 changes: 20 additions & 1 deletion lua/lint/linters/golangcilint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ local severities = {
convention = vim.diagnostic.severity.HINT,
}

local find_go_mod_dir = function(start_dir)
local dir = start_dir or vim.fn.getcwd()
local parent = dir

while true do
local go_mod_path = parent .. '/go.mod'
local file = io.open(go_mod_path, 'r')
if file then
file:close()
return parent
end
local next_parent = vim.fn.fnamemodify(parent, ':h')
if next_parent == parent then
return nil -- reached filesystem root without finding go.mod
end
parent = next_parent
end
end

-- Gets the correct arguments to run based on the version of golangci-lint
local getArgs = function()
local ok, output = pcall(vim.fn.system, { 'golangci-lint', 'version' })
Expand Down Expand Up @@ -44,7 +63,7 @@ local getArgs = function()
'--issues-exit-code=0',
'--show-stats=false',
function()
return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ":h")
return find_go_mod_dir(vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ':p')) .. '/...'
end,
}
end
Expand Down