Golangci-lint: confusing error message "File is not goimports-ed (goimports)"

Created on 29 Jun 2018  ·  20Comments  ·  Source: golangci/golangci-lint

A file not being "goimports-ed" is a little confusing. Can we adjust this error message to something a little clearer like "File has not been formatted (goimports)"

enhancement

Most helpful comment

now it's too late to change it: some users have already added this text to exclude list.

This way we can never improve error message 😇

All 20 comments

hi!
it's the good idea, but
now it's too late to change it: some users have already added this text to exclude list.

now it's too late to change it: some users have already added this text to exclude list.

This way we can never improve error message 😇

You are right, I got an idea to mark it as v2: in the next version (not in the roadmap yet) we can break compatibility and implement id.

Is this using some custom version of goimports? I recently had it complain about one import even though the file was formatted by goimports. Turned out it wanted me to move it to another group of imports (even though regular goimports doesn't move imports between groups).

This has started to happen to me since 1.24+. Running GolangCI with goimports suggests files aren't properly formatted even though running both gofmt and goimports manually on the files golangci complains about results in no changes and both tools exiting with a status code of 0.

Same here (but I'm a new user).
It complains for imports containing the - character, such as:

  • github.com/opentracing/opentracing-go
  • github.com/getsentry/raven-go
  • github.com/michaelklishin/rabbit-hole
  • github.com/oschwald/geoip2-golang

@qfel @daenney @pierrre do you use updated goimports? Did you run go get -u golang.org/x/tools/cmd/goimports?

also, let's continue in https://github.com/golangci/golangci-lint/issues/347,
this issue about message text

I just ran into this problem too. A better message would have gotten me to a fix quicker.

+1; Human readable message is expected and "File is not goimportes-ed" confused me

  1. What message do you want to see? Please, run goimports tool for this file?
  2. Have you tried --fix option?

The message should explain what the problem is (e.g. missing an import statement for package x.) It could also maybe propose a solution like, add the import statement or rungoimportsto add missing import statements. It should not just print what the solution is, because it may not be clear what the problem is for those unfamiliar with the suggested tool.

@bcomnes, import statement != goimports, looks like the tool should be renamed, not a message.

In addition to fixing imports, goimports also formats your code in the same style as gofmt

i have the same error, but run goimports -w on file does not bring any differences.

Is there any update on this? Maybe it makes sense to at least add documentation to this check?

Right now, it reports two lines in my project and I have no idea what it means and how to resolve them (go fmt ./... doesn't change anything and the imports are obviously needed).

@qfel @daenney @pierrre do you use updated goimports? Did you run go get -u golang.org/x/tools/cmd/goimports?

also, let's continue in #347,
this issue about message text

I came across the same issue. It was being fixed by the following steps:

  1. go get -u golang.org/x/tools/cmd/goimports
  2. go mod tidy
  3. go mod vendor
  4. go fmt //==> formatting code
  5. goimports -w ==> clean imports
  6. gofmt -s -w ==> simplify code

@samurnin, the goimports -w is not just managing imports, it's also doing the same formating as regular gofmt -w. P.S. thanks for -s flag.

Built-in and non-built-in packages should be separated and the built-in packages placed first
内置包和非内置包应该要分开,内置包放在前面,自己的外部包放后面,例如

import (
    "fmt"
    "net/http"

    "github.com/containers/podman/v2/libpod/define"
    "github.com/containers/podman/v2/pkg/domain/entities"
    "github.com/pkg/errors"
    log "github.com/sirupsen/logrus"
)

+1 for @samurnin for the details steps. goimports -w filename.go fixed it for me. In the end it was what @zhangguanzhang suggested.

Built-in and non-built-in packages should be separated and the built-in packages placed first

"File is not goimports-ed (goimports)" is a really bad message, confusing, wasting time trying to understand what it means.

Echoing the "what? my vim config runs gofmt automatically, and _it_ doesn't care, so why the hell does golangci?" sentiment. The error

now it's too late to change it: some users have already added this text to exclude list.

@jirfag да блин, кто они? наверно, если эти юзери, ну «перегрузить» бы свои exclude lists, многие другие юзери улыбнулись бы 🤣 ))))))

It's not immediately obvious what to do when this occurs (simply running goimports prints a fixed version to stdout, which neither fixes the issue nor makes it clear where it is). Perhaps:

<file> has improperly-formatted imports. Run `goimports -d <file>` to see the issue or `goimports -w <file>` to fix it in-place.

That offers both a command that shows the issue only, and a command that will just fix it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KeepMasterBranch picture KeepMasterBranch  ·  3Comments

atc0005 picture atc0005  ·  4Comments

kpeu3i picture kpeu3i  ·  3Comments

simonpasquier picture simonpasquier  ·  4Comments

bacongobbler picture bacongobbler  ·  4Comments