Comments (12)
I suggest doing whatever gofmt/goimports do today.
FWIW we've used this scheme for many years and have had zero tooling problems due to it. We might change our paths when we move to modules, but for now I see no point in making up faking TLD-based import paths for packages that aren't publicly accessible on the internet anyway.
from gofumpt.
This is because it assumes imports with no domain extension belong in the standard library. I'm pretty sure this is the same rule that the go tool applies; any import with no TLD might be broken at any point.
from gofumpt.
I'm pretty sure this is the same rule that the go tool applies; any import with no TLD might be broken at any point.
Citation?
from gofumpt.
Uh, I'm not sure! I'll get back to you on this :)
from gofumpt.
So it turns out there's no official docs on this. I only knew this from interactions with Bryan on GitHub and Slack. I've opened golang/go#32819.
I'll keep this issue open for now, but I'm not sure if this can be done any other way in the future. Hard-coding a list of std
is tedious and sloppy, and calling go list std
is (relatively) expensive.
from gofumpt.
I am indeed following what goimports
does:
$ cat f.go
package p
import (
"io"
"might/be/standard"
"foo.com/bar"
)
var (
_ = io.Var
_ = standard.Var
_ = bar.Var
)
$ goimports f.go
package p
import (
"io"
"might/be/standard"
"foo.com/bar"
)
var (
_ = io.Var
_ = standard.Var
_ = bar.Var
)
You're only seeing problems here because gofumpt
uses the distinction in one more way - to join the std group. goimports
only uses the distinction to separate std imports from non-std ones.
from gofumpt.
I see. I didn't realize that gofumpt tries to do extra stuff with imports since that wasn't in the list of features.
from gofumpt.
You're right! I must have forgotten to add that bit.
from gofumpt.
Anyway, I think that the fix here is indeed to know what is and is not in std rather than guess based on this heuristic.
But even without doing that, ISTM that if I provide gofumports with -local liftoff/
, as I did, that should take precedence over the std heuristic.
from gofumpt.
I think that the fix here is indeed to know what is and is not in std
I just don't think that's practical in the long term. Even if I take the time to keep the list up to date with time, what if a user has a version of the tool that's too old or too new? It could lead to surprising behavior.
In contrast, this heuristic is simple and shouldn't surprise anyone, if the doc issue above is fixed. If anyone wants to stick to these grey-area import paths for the time being, that's fine; they know what they are doing.
that should take precedence over the std heuristic.
That seems reasonable. Just bear in mind that only gofumports
has the flag, so gofumpt
would still annoy you. So it doesn't seem like a long-term fix to me, unless you're happy with only using gofumports
.
from gofumpt.
The upstream issue was labeled NeedsFix, so it looks like my thinking was correct. I'll close this as "works as intended" for now. Thanks for bringing it up though, as the documentation was lacking in both this repo and upstream.
from gofumpt.
FYI, see #187 (comment); I'm currently thinking we could do better for everyone by looking at the main module's path.
from gofumpt.
Related Issues (20)
- panic while handling some //line directives HOT 2
- Breaks import comment HOT 1
- feature: Enforce line breaks between multiline function calls with func() argument HOT 1
- add simplifications for Go 1.22 HOT 1
- panic: invalid semver string: "v1.22rc2" HOT 1
- Making every added formatting rule Optional HOT 3
- missing binary release at latest version-v0.6.0 HOT 1
- Single import should not be grouped with parentheses
- Generated file not ignored HOT 2
- prevent indentation confusion
- Gofumpt removing newlines before comments HOT 7
- gofumpt is very slow when `go` is behind an asdf shim HOT 3
- Split long lines only available behind environment string
- Publish v1 HOT 2
- how to ignore certain folders? HOT 8
- Alias imported package to match the package name
- Group adjacent short variable declarations HOT 1
- Import grouping vs internal HOT 5
- Option to disable imports processing HOT 2
- octal notation with people misusing date.Time HOT 5
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.