Hi,

I don't think that error message comes from gofmt. As far as I am aware,
gofmt only parses source code, it does not even do type-checking.
That is intentional - in general, Go tools tend to avoid relying on
stronger assumptions than they need. So I would assume that this error
message is produced by the editor running `go build` or something similar,
which does need to check imports for correctness. And because it requires
that, it seems unlikely that the error would be able to go away. Of course,
the editor could stop running that command in that context or suppress that
error message itself.

FWIW you might be interested in https://github.com/golang/go/issues/48429,
which gives a less hacky way to track tool dependencies and which (as far
as I know) has been accepted and is being implemented, with some delays due
to team changes. So, for the concrete issue, a solution is already being
worked on.

On Fri, 30 Aug 2024 at 03:54, Mike Schinkel <m...@newclarity.net> wrote:

> Hi all,
>
> I think I already know the answer, but hoping there is a way I am missing
> to get gofmt to stop generating the "import in a program, not an importable
> package" error when parsing a `tools.go` file with the `tools` build tag.
>
> If you are not familiar, there is an approach several people have written
> about to store references to your project's required Go-based CLI tools in
> a `tools.go` file:
>
> https://play-with-go.dev/tools-as-dependencies_go119_en/
> https://www.jvt.me/posts/2022/06/15/go-tools-dependency-management/
>
> I am using it because oapi-codegen recommends it for maintaining enabling
> others who may clone your repo to easily get the proper tools then need
> installed:
>
> https://github.com/oapi-codegen/oapi-codegen/?tab=readme-ov-file#install
>
> And grpc-gateway evidently recommends it too:
>
> https://github.com/grpc-ecosystem/grpc-gateway#installation
>
> When I run gofmt — which GoLand does prior to a commit — it generates that
> as an error.  People have said just to ignore it:
>
> https://github.com/grpc-ecosystem/grpc-gateway/issues/3515
>
> https://stackoverflow.com/questions/77664121/import-is-a-program-not-an-importable-package
>
> However — call me anal —I really want to ensure no errors are generated
> unless they are errors I really need to fix. Otherwise I will likely get
> complacent and accidentally commit a real error.
>
> Is there any way to get gofmt to ignore code based on build tags, e.g.
> `tools` in this case?
>
> -Mike
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/31160B8D-8DBC-43C7-8396-F74B2B8AFD92%40newclarity.net
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfE0n3k76CXdWR%2BtuS5bOUB1CjS1Pymz6EVGhauDJMcxWg%40mail.gmail.com.

Reply via email to