The other day, I was linting my Go code with golangci-lint when I got this error:
File is not `goimports`-ed (goimports)
I examined the file and found nothing amiss, but the linter insisted something was wrong.
Eventually, I realized I had used spaces to indent the file rather than tabs. Changing the indent character to tabs fixed it.
I then ran into the same error on a second file. This time, I had a comment which was wrong. There were two spaces before the first word in the comment (see below).
Example:
// Thing is a struct which holds info! <-- 2 spaces after double slashes!
type Thing struct {
Stuff string
MoreStuff int
}
Removing the double-space fixed it.
So, to fix this error:
- Tab-indent your Go files
- Don’t have two spaces before your comments