Skip to content
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

proposal: x/tools/cmd/goimports: support multiple groups for imported packages via -local #60907

Open
uynap opened this issue Jun 21, 2023 · 2 comments
Labels
Milestone

Comments

@uynap
Copy link

uynap commented Jun 21, 2023

Hi,

I would like to automatically group the imported packages into 4 groups.

// standard packages

// third party packages

// company private packages

// current code base

It can't be done by the current goimports, because the -local for the goimports only gets a string.
For example, I have a go source file below:

package Foo

import (
    "fmt"
    "github.com/google/uuid"
    "github.com/company/private/database"
    "github.com/current/codebase/pkg/utils"
)

By using goimports -local github.com/current foo.go, I will have:

package Foo

import (
    "fmt"

    "github.com/google/uuid"
    "github.com/company/private/database"

    "github.com/current/codebase/pkg/utils"
)

I want goimports can support the arguments like: goimports -local github.com/current -local github.com/company foo.go.
The expectation is as below.

package Foo

import (
    "fmt"

    "github.com/google/uuid"

    "github.com/company/private/database"

    "github.com/current/codebase/pkg/utils"
)

My requested feature is NOT a breaking change, it's back compatible.
I think it should be a simple change. If you are ok for the feature, I will provide the implementation with testing.

TIA.

@uynap uynap added the Proposal label Jun 21, 2023
@gopherbot gopherbot added this to the Proposal milestone Jun 21, 2023
@seankhliao seankhliao changed the title proposal: goimports: Support multiple groups for imported packages via -local proposal: x/tools/cmd/goimports: Support multiple groups for imported packages via -local Jun 21, 2023
@seankhliao seankhliao changed the title proposal: x/tools/cmd/goimports: Support multiple groups for imported packages via -local proposal: x/tools/cmd/goimports: support multiple groups for imported packages via -local Jun 21, 2023
@ianlancetaylor
Copy link
Contributor

CC @bradfitz

@violin0622
Copy link

There's already an implementation which may help:
https://github.com/daixiang0/gci?ref=javorszky.co.uk

I'm looking forward goimports to support company group too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

4 participants