(This proposal is the first of a sequence of two; https://github.com/golang/go/issues/71859 is the second.)

Background: The go fix subcommand was an important tool during the early days of Go to help early adopters deal with rapid changes, not always compatible, in the evolving language. It currently contains these features:

  • buildtag: remove old-style +build tags.
  • cftype: Fixes initializers and casts of C.*Ref and JNI types
  • context: Change imports of golang.org/x/net/context to context
  • egl: Fixes initializers of EGLDisplay
  • eglconf Fixes initializers of EGLConfig
  • gotypes: Change imports of golang.org/x/tools/go/{exact,types} to go/{constant,types}
  • jni: Fixes initializers of JNI's jobject and subtypes
  • netipv6zone: Adapt element key to IPAddr, UDPAddr or TCPAddr composite literals
  • printerconfigFix: Add element keys to Config composite literals

I think all of these have outlived their usefulness, with the possible exceptions of the first, which could be converted to the analysis framework, and the last, which already has been.

This paves the way for a future proposal to add new functionality to go fix to make it invoke the analysis framework (as vet does), but instead of reporting diagnostics, it would batch-apply safe fixes such as those produced by these analyzers:

  • gofix (which probably wants to be renamed to inline)
  • assign
  • hostport
  • timeformat
  • maprange
  • modernize
  • simplifycompositelit
  • simplifyrange
  • simplifyslice
  • unusedparams

Proposal: We propose to remove all functionality from go fix, so that it simply prints an error message.

Related: - https://github.com/golang/go/issues/70815 - https://github.com/golang/go/issues/32816 - https://github.com/golang/go/issues/71859

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: seankhliao

I'm not sure it's a good idea to make it error? It seems to be part of people's workflows, especially when combined with other commands like go mod tidy.

Makefiles: https://github.com/search?q=language%3AMakefile+%2F%5E%5Ctgo+fix%2F&type=code Shell: https://github.com/search?q=language%3Ashell+%2F%5E%5Cs*go+fix%2F&type=code

Comment From: rsc

Indeed, even an empty "go fix" should not error out. The buildtag fix should be kept in some form, and the context and gotypes fixes should be kept in the form of //go:fix annotations in the old packages.

Comment From: aclements

It seems like it would be easy to clear out fix without breaking compatibility and still set ourselves on a path to rejuvenate it. The go fix command just takes a list of packages and, optionally, a -fix list flag. We want to keep at least buildtag and printerconfigFix. It's probably easy to keep the -fix flag working and just make the other fixers no-ops. (I'm not worried about keeping cmd/fix itself compatible, which is good because it takes a list of file paths, not packages, which would be far more annoying to keep working.)

Comment From: aclements

This proposal has been added to the active column of the proposals project and will now be reviewed at the weekly proposal review meetings. — aclements for the proposal review group