Closed nchepanov-plaid closed 5 months ago
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.
Hello,
buildir
detects compilation errors.
package main
import _ "github.com/go-delve/delve/cmd/dlv"
$ go build
main.go:4:8: import "github.com/go-delve/delve/cmd/dlv" is a program, not an importable package
This error is expected because github.com/go-delve/delve/cmd/dlv
is a main
package so it cannot be imported.
nolint
directives cannot be used to ignore compilation errors.
You are misusing the tools pattern: this pattern required a dedicated file (ex: tools.go
) and a dedicated build tag (//go:build tools
).
I recommend not using this pattern because it has side effects (ex: dependencies of a tool can change the dependencies of another tool).
Ah, this makes sense! Thank you!
Unfortunately even with correct usage of the pattern I'm still seeing the linter error, and I understand that the linter error just points at the build error: not an importable package
.
What do you suggest to use instead of the tools pattern? In my case I use Bazel to read go.mod
and go.mod
is automatically populated by go mod tidy
. Are you aware of other ways to include an installable go package into a repository?
Unfortunately even with correct usage of the pattern I'm still seeing the linter error,
It works if you don't use the build tags with golangci-lint:
$ golangci-lint run
$
If I use the build tag to run golangci-lint:
$ golangci-lint run --build-tags tools
tools.go:5:8: import "github.com/go-delve/delve/cmd/dlv" is a program, not an importable package (typecheck)
import _ "github.com/go-delve/delve/cmd/dlv"
^
$
If I remove the directive //go:build tools
:
$ golangci-lint run
tools.go:3:8: import "github.com/go-delve/delve/cmd/dlv" is a program, not an importable package (typecheck)
import _ "github.com/go-delve/delve/cmd/dlv"
^
$
What do you suggest to use instead of the tools pattern?
It's a personal preference, but I just install tools locally with go install
.
You can use a script, or a make target, or something else to automate that if you want.
Welcome
Description of the problem
In my go repository I need to add
delve
to go.mod.Since
delve
is a tool, the recommended way of doing it is including a noopimport
(see reproducer). Everything works as expected except that the linter now breaks in very strange way that I wasn't able to work around.Version of golangci-lint
Configuration
Go environment
Verbose output of running
A minimal reproducible example or link to a public repository
Validation