Skip to content

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

@uynap

Description

@uynap

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions