Coder Social home page Coder Social logo

Comments (6)

mvdan avatar mvdan commented on May 26, 2024

I agree. Where possible, we should enforce the new syntax.

There is only one wrinkle - this syntax requires Go 1.13 or later as a toolchain and on go.mod, so forcing this on a module that has go 1.12 or earlier on their go.mod would break the module.

I think a direction for gofumpt could be to start being module-aware, even if it's only optionally. Then we can make better decisions like "are these imports from the main module", or "can we use this language feature", among many other questions that gofmt can't have an answer to.

from gofumpt.

mvdan avatar mvdan commented on May 26, 2024

Another option is that, since we only support the latest two major Go versions, we can wait a few more months and then just start enforcing this all the time.

If someone is stuck on Go 1.12 or earlier, they can simply pin an older version of gofumpt.

from gofumpt.

twpayne avatar twpayne commented on May 26, 2024

The last two major Go versions are Go 1.13 and Go 1.14, and the 0o prefix was introduced in Go 1.13 so can we implement this now or am I missing something?

from gofumpt.

mvdan avatar mvdan commented on May 26, 2024

Yes, we could in theory do it now. In practice, I'd prefer to wait a bit longer to not annoy too many people. 1.12 is still maintained by the Go project until 1.15 is out, and some users are slow to upgrade.

from gofumpt.

twpayne avatar twpayne commented on May 26, 2024

OK.

Would you consider either of the following?

  • Making this behavior configurable with a command line flag?
  • An abomination of a PR that uses the go1.15 build flag to automatically enable and disable this behavior, allowing the user to enable it manually by enabling the go1.15 build tag when compiling with Go 1.14. I cringe horribly just thinking about it, but it does work.

from gofumpt.

mvdan avatar mvdan commented on May 26, 2024

I don't think this feature warrants a command line flag. Like I mentioned before, the correct way to do the right thing would be to look at go.mod, but that would first require refactoring the tool a bit to be module-aware.

However, I'm OK with adding a "go version" argument to the internal API. That way, once the external tool starts grabbing the version from go.mod, it can pass the version along. The same could apply to other tools like gopls, if they integrate the gofumpt internals in the future.

For now, we can just make our gofumpt tool always pass go 1.15. The format should be a string, matching what go list -m -json shows for a module:

$ go list -m -json
{
	"Path": "mvdan.cc/sh/v3",
	"Main": true,
	"Dir": "/home/mvdan/src/sh",
	"GoMod": "/home/mvdan/src/sh/go.mod",
	"GoVersion": "1.14"
}

Semver comparisons would be a bit awkward, but you can reuse https://godoc.org/golang.org/x/mod/semver.

from gofumpt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.