-1

In Go 1.17, gofmt automatically changes my files:

//go:build test
// +build test

I've uninstall Go 1.17 and re-installed 1.16, but the problem continues. How do I stop it?

I should say that I cannot use these tags, because the codegen we are using (which I cannot change) considers them an error and fails builds.

blackgreen
  • 34,072
  • 23
  • 111
  • 129
Alex Collins
  • 980
  • 11
  • 23
  • 5
    What's wrong with it? `go:build` is the new and preferred form. They will replace the build tags, so you should be thanking the go tool for helping the transition. – icza Sep 14 '21 at 15:30
  • 5
    You can't/shouldn't. This is the new recommended more flexible format for build parameters. – colm.anseo Sep 14 '21 at 15:31
  • 4
    https://golang.org/doc/go1.17#build-lines: _"To aid in migration, `gofmt` now automatically synchronizes the two forms"_, and also – JimB Sep 14 '21 at 15:34
  • 1
    Related: https://stackoverflow.com/questions/68360688 , specifically to see why it is generally better than `+build` – blackgreen Sep 14 '21 at 19:42

2 Answers2

1

gofmt will only add the new format if it detects the old format; if it only sees the new format - it will not add the old format.

So, if you know you are building using go 1.17 (or later), you can drop the now legacy build constraint line:

// +build test

and migrate fully to the new build constraint format:

//go:build test

to just have a single build constraint line in your source.

colm.anseo
  • 19,337
  • 4
  • 43
  • 52
0

The solution is to downgrade to Golang 1.16, but check that the links to tooling have been correctly changed back.

Alex Collins
  • 980
  • 11
  • 23