8000 sort imports using LocalPrefix by Thearas · Pull Request #2171 · ent/ent · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Closed
wants to merge 3 commits into from
Closed

Conversation

Thearas
Copy link
@Thearas Thearas commented Nov 26, 2021

Implement #2170.

The second commit is generated by go generate ./....

Copy link
Collaborator
@masseelch masseelch left a 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>
@a8m
Copy link
Member
a8m commented Nov 26, 2021

I like very much. Let's see what @a8m thinks.

Thanks for your contribution @Thearas, and for your review @masseelch ❤️

Please, see my comment on #2170 (comment), and let's continue the discussion there.

Comment on lines 18 to +22
"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"
Copy link
Member

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?

Copy link
Collaborator
@masseelch masseelch Nov 26, 2021

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 😜

Copy link
Author
@Thearas Thearas Nov 26, 2021

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).

Copy link
Author

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.

Copy link
Member

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.

Copy link
Member

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?

Copy link
Author

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😂.

Copy link
Author

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 !

@Thearas Thearas closed this Nov 26, 2021
@Thearas Thearas deleted the sort-imports branch November 26, 2021 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0