Comments (6)
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.
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.
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.
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.
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 thego1.15
build tag when compiling with Go 1.14. I cringe horribly just thinking about it, but it does work.
from gofumpt.
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)
- gofumpt's behaviour depends on the version of Go used to build it HOT 10
- gofumpt doesn't work with neovim HOT 3
- whitespace around multiplication operator HOT 1
- gofumpt lint conflict with go-swagger comments HOT 2
- CLI argument to ignore paths HOT 13
- Support running controversial/experimental rules individually HOT 1
- How do I use "-extra" in VS Code HOT 1
- ldflags failed for gofumpt 0.4.0 release HOT 4
- gofumpt re-formats tabs to spaces (was: New release built with go 1.19?) HOT 3
- Groups with comments below single var declaration are unexpectedly formatted HOT 1
- Provide pre-commit hook configuration HOT 3
- Does gofumpt ignore folders like testdata? HOT 2
- Multiline blocks allow newline before closing brace HOT 1
- Enforce some consistency with newlines at the start and end of parameter lists HOT 3
- Unnecessary newline in arguments when putting type parameters on a separate line
- Document WHEN generated code is touched and how to mitigate it HOT 2
- gofumpt badge HOT 1
- Fails to install with Go 1.20.3 HOT 1
- Panic on formatting of multiple files
- Don't group variables when //go:embed is present. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gofumpt.