How do I fix File is not `goimports`-ed with -local?

1.5k Views Asked by At

How do I fix this error?

pkg/path/to/file.go:22: File is not `goimports`-ed with -local github.com/some/repositiory (goimports)
        s "github.com/some/repositiory/pkg/somepkg"

If I run goimports -local pkg/path/to/file.go the program just seems to get stuck and nothing happens.

s is the name I use to refer to somepkg, e.g. s.SomeFunc().

2

There are 2 best solutions below

0
On

Another solution is to run golangci-lint on your file:

golangci-lint run --fix

For me, the fix was adding a new line between the import:

    sprig "github.com/go-task/slim-sprig"
+
    "github.com/kubeshop/testkube/pkg/api/v1/testkube"
2
On

You have to run

goimports -w -local github.com/some/repositiory pkg/path/to/file.go