Closed Integralist closed 1 year ago
I've also just tried with a fresh project:
package main
func main() {
fmt.Println("hello world")
}
The fmt
package wasn't auto-imported when writing to the file, and so an error was presented:
undeclared name: fmt
Again this suggests the goimports
tool isn't being run when I would expect it to.
But then I went to check for a code action on the fmt.Println
line and there were two options shown...
(quickfix) Add import: "fmt"
(source.organizeImports) Organize Imports
Once I selected one of the options, and the package was imported for me, the error disappeared obviously, but then I saw the following error:
File is not `gofumpt`-ed gofumpt [6, 1]
Do I read this right that this was a golangci-lint issue, and that this is resolved?
I'm trying to use nvim-lint to run golangci-lint (discussion) but it's not working 😞
This is what I have at the moment
Here is my
golangci-lint
configuration file~/.golangci-lint
:Here is an example code file that has some issues:
From what I can tell the fundamental problems are gofumpt and goimports aren't running when expected.
The io/os packages did eventually get dynamically added as imports when I typed os.ErrClosed and io.ErrClosedPipe. But for some reason the fmt package would not get added at all no matter how many times I typed a line consisting of that package.
This suggests the goimports tool isn't always being run when it should (e.g. when the file is being written to/updated).
I also noticed that when imports are dynamically added, then the order of the imports were also being sorted correctly (again, that's a side effect of goimports actually being run but just something I wanted to note).
So why does typing any kind of fmt line, like
fmt.Println(...)
not import that package?Here is my neovim configuration:
Here is the output of manually running the
golangci-lint run
command and it shows that we have the various linters enabled (sure some are disabled due to go1.18, but none of the ones I've commented in the above code as not working have been disabled so those should have run):Other neovim configuration I have is (this was placed after the above neovim configuration in my
~/.config/nvim/init.vim
file but I've since moved thelspconfig
setup to be before it, just in case it made any difference -- it didn't):