Open wiegell opened 1 year ago
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.
The go version is extracted from the go.mod
of the module and used by gofumpt.
module-path
is empty by default.
I think the problem is not really related to module-path
but to the detection of the go.mod
inside a workspace.
Can you provide a fully reproducible example?
Note: golangci-lint is not able to run on all modules of a workspace in one run.
I could reproduce this issue both locally and in the CI.
Probably the same issue here: https://github.com/exoscale/egoscale/pull/631
I can also reproduce locally, what is weird is, when I run goimports v3/generator/schemas/schemas.go
on the go file,
there is exactly no diff.
golangci-lint run --timeout 5m ./v3/...
WARN [config_reader] The configuration option `run.skip-dirs` is deprecated, please use `issues.exclude-dirs`.
v3/generator/schemas/schemas.go:10: File is not `goimports`-ed with -local github.com (goimports)
The output is saying line 10 in schemas.go
package schemas
import (
"bytes"
"fmt"
"go/format"
"log/slog"
"os"
"strings"
"github.com/exoscale/egoscale/v3/generator/helpers"
"github.com/pb33f/libopenapi"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/libopenapi/orderedmap"
"gopkg.in/yaml.v3"
)
line 10 is the space automatically formatted by gofmt between:
"strings"
"github.com/exoscale/egoscale/v3/generator/helpers"
Note: not very useful but this fix the lint errors (not the right solution)
package schemas
import (
"bytes"
"fmt"
"go/format"
"log/slog"
"os"
"strings"
// nolint: goimports
"github.com/exoscale/egoscale/v3/generator/helpers"
"github.com/pb33f/libopenapi"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/libopenapi/orderedmap"
"gopkg.in/yaml.v3" // nolint: goimports
)
Probably you have an idea on this, thank you!
@pierre-emmanuelJ Your problem is related to your configuration: https://github.com/exoscale/egoscale/blob/192c5a5e661a6a04b789e68755e2af830ea4061e/.golangci.yml#L7-L8
Run the following command:
golangci-lint run --enable-only goimports --fix
I think your configuration is not "logical": a local prefix is for the module name (ex: github.com/exoscale/egoscale
) or the organization (ex: github.com/exoscale
).
The fact that using github.com
as a prefix, required splitting the import like this:
import (
"bytes"
"fmt"
"go/format"
"log/slog"
"os"
"strings"
"gopkg.in/yaml.v3"
"github.com/exoscale/egoscale/v3/generator/helpers"
"github.com/pb33f/libopenapi"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/libopenapi/orderedmap"
)
I recommend changing your configuration to:
linters-settings:
goimports:
local-prefixes: github.com/exoscale/egoscale
or just remove this configuration because std imports and external imports are always splitted.
Thanks, @ldez :) I'll apply your suggestion
I was using gofumpt and it would accidentally cause import to be removed, when I removed gofumpt it all worked fine!
Welcome
Description of the problem
The problem has already been discussed in detail here: #2711
Golangci-lint sorts imports differently than standalone gofumpt. This is especially an issue when using vs code, where gopls (gofumpt) therefore formats the imports in a way that is invalid in CI-run of gofumpt (via golangci-lint).
When doing a:
//gofumpt:diagnose
One can see, that thegolangci-lint --fix
does not find themodpath
automatically if not explicitly set in the lint-settings in.golangci.yaml
. Because of this, it is not supported to have one common.golangci.yaml
in a workspace, but instead multiple are needed - one for each module, which is not very dry.Version of golangci-lint
Configuration
Go environment
Verbose output of running
Code example or link to a public repository
Validation