Skip to content

Goimports error message insufficient with local-prefixes #773

Closed
@ian-howell

Description

@ian-howell

The error message for goimports is currently insufficient when run with a local-prefixes. Suppose we have the following:

main.go:

package main

import (
        "fmt"

        "github.com/ian-howell/foo/pkg"
        "github.com/spf13/cobra"
)

func main() {
        fmt.Println(pkg.Foo())
        _ = cobra.Command{}
}

.golangci.yaml:

linters-settings:
  goimports:
    local-prefixes: github.com/ian-howell/foo
linters:
  disable-all: true
  enable:
    - goimports

Running golangci-lint run -c .golangci.yaml produces the following output:

main.go:6: File is not `goimports`-ed (goimports)
        "github.com/ian-howell/foo/pkg"

This message is confusing, because running goimports on the file doesn't seem to find any issues:

$ diff <(goimports main.go) main.go
$ # no output

Of course, running goimports with the -local flag does provide output, but golangci-lint does not indicate that the flag is needed:

$ diff <(goimports -local github.com/ian-howell/foo main.go) main.go
6,7d5
<       "github.com/spf13/cobra"
<
8a7
>       "github.com/spf13/cobra"

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions