mvdan / gofumpt

A stricter gofmt
https://pkg.go.dev/mvdan.cc/gofumpt
BSD 3-Clause "New" or "Revised" License
3.15k stars 110 forks source link

Don't group variables when //go:embed is present. #270

Closed perrito666 closed 1 year ago

perrito666 commented 1 year ago

What steps will reproduce the issue?

Note I triggered this using gofumpt through goland but deactivating gofumpt as a watcher solves the issue so I suspect it is caused by it.

  1. Declare variables with // go:embed directive, like so:

    //go:embed some.html.template
    var someTemplate string
    var otherVariable = "something"
  2. Save

What is the expected result?

As //go:embed expects to be above a single variable, the above declaration should be left as is (or otherVariable grouped with subsequent variables if any)

What happens instead?

//go:embed some.html.template
var (
    someTemplate string
    otherVariable         = "something"
)

Which triggers the error go:embed must be placed above a declaration of a single global variable

mvdan commented 1 year ago

which gofumpt version are you on? this should have been fixed a long time ago, with https://github.com/mvdan/gofumpt/issues/126. you can extract the version you're actually using via https://github.com/mvdan/gofumpt#contributing.

perrito666 commented 1 year ago

🤦 ok I might be at fault here

This is the version that was being used by goland

➜ gofumpt /tmp/f.go
package p

//gofumpt:diagnose

This is the system version

➜ gofumpt /tmp/f.go
package p

//gofumpt:diagnose version: v0.5.0 (go1.20.3) flags: -lang=v1 -modpath=

After getting rid of the spurious binary and pointing goland to the system one It works, sorry for the unnecessary noise