Closed troyanov closed 8 months ago
This PR allows golangcilint to use provided cwd instead of vim.fn.getcwd() using functionality that was added in https://github.com/mfussenegger/nvim-lint/pull/358
golangcilint
cwd
vim.fn.getcwd()
It might be helpful for a monorepo with multiple languages.
project-root ├── .golangci.yaml ├── client │ └── lxc.py ├── agent │ ├── go.mod │ └── cmd │ └── main.go └── core ├── go.mod └── main.go
If my vim.fn.getcwd() will be project-root I won't be able to run golangcilint since it will fail to find any Go modules
project-root
ERRO [linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies
However, with some auto commands I can search for go.mod among ancestors that are related to my buffer path:
go.mod
vim.api.nvim_create_autocmd({ 'BufEnter' }, { pattern = { '*.go' }, callback = function() local lsputil = require('lspconfig.util') local cwd = lsputil.root_pattern("go.mod")(vim.fn.expand('%:p')) local config = lsputil.root_pattern(".golangci.yaml")(vim.fn.expand('%:p')) local golangcilint = require('lint.linters.golangcilint') golangcilint.args = { 'run', '--out-format', 'json', '--timeout', '5m', } if config ~= nil then config = config .. '/.golangci.yaml' table.insert(golangcilint.args, '--config') table.insert(golangcilint.args, config) end golangcilint.cwd = cwd end, })
This PR allows
golangcilint
to use providedcwd
instead ofvim.fn.getcwd()
using functionality that was added in https://github.com/mfussenegger/nvim-lint/pull/358It might be helpful for a monorepo with multiple languages.
If my
vim.fn.getcwd()
will beproject-root
I won't be able to rungolangcilint
since it will fail to find any Go modulesHowever, with some auto commands I can search for
go.mod
among ancestors that are related to my buffer path: