-
Notifications
You must be signed in to change notification settings - Fork 964
sort imports using LocalPrefix #2171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like very much. Let's see what @a8m thinks.
Co-authored-by: MasseElch <12862103+masseelch@users.noreply.github.com>
Thanks for your contribution @Thearas, and for your review @masseelch ❤️ Please, see my comment on #2170 (comment), and let's continue the discussion there. |
"entgo.io/ent/entc/integration/ent/role" | ||
"entgo.io/ent/entc/integration/ent/schema" | ||
"entgo.io/ent/entc/integration/gremlin/ent/fieldtype" | ||
"github.com/google/uuid" | ||
|
||
"entgo.io/ent/entc/integration/gremlin/ent/fieldtype" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In such cases, the generated package imports a "local package". Therefore, the grouping should be based on the Go modules (project root). In this case, it's entgo.io/ent
. i.e. if we have 2 import paths:
<root-pkg>/ent/user
<root-pkg>/pkg/types
We want to set -local
to <root-pkg>
, and not <root-pkg>/ent
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahm, yeah. goimports
needs an option to add a 4th section -> generated 😜
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree😁. But I found it's hard to decide the <root-pkg>
in the project using nested modules. Maybe it's better to let user to decide the LocalPrefix
. Like @a8m said in #2170 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another idea, entc
will set LocalPrefix
to <root-pkg>
only if the LocalPrefix
is empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add some code for loading the Go module information (see my PR - #2175) and use it as a LocalPrefix, but I agree it should be set only if LocalPrefix
is empty. Let me know what do you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Module.Path
should return the go module path. But again, tbh, I think there are no real guidelines on how package paths should be grouped. I, for example, like to group all my company/product import paths in the same block. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I have already fixed my problem with imports.LocalPrefix = "<config-goes-here>"
. This PR could be closed😂.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your solution @a8m !
Implement #2170.
The second commit is generated by
go generate ./...
.