daixiang0 / gci

GCI, a tool that control golang package import order and make it always deterministic.
BSD 3-Clause "New" or "Revised" License
434 stars 63 forks source link

Feature Request: treating aliased imports separately #175

Closed dhrubabasu closed 1 year ago

dhrubabasu commented 1 year ago

Thanks for the package, this solves nearly all our problems w.r.t. import sorting ❤️

What are your thoughts about treating aliased imports separately? (maybe through a separate config)

Feeding this to gci:

import (
    "context"

    "github.com/ava-labs/avalanchego/api/keystore"
    "github.com/ava-labs/avalanchego/database"
    "github.com/ava-labs/avalanchego/database/rpcdb"
    "github.com/ava-labs/avalanchego/vms/rpcchainvm/grpcutils"

    keystorepb "github.com/ava-labs/avalanchego/proto/pb/keystore"
    rpcdbpb "github.com/ava-labs/avalanchego/proto/pb/rpcdb"
)

yields:

import (
    "context"

    "github.com/ava-labs/avalanchego/api/keystore"
    "github.com/ava-labs/avalanchego/database"
    "github.com/ava-labs/avalanchego/database/rpcdb"
    keystorepb "github.com/ava-labs/avalanchego/proto/pb/keystore"
    rpcdbpb "github.com/ava-labs/avalanchego/proto/pb/rpcdb"
    "github.com/ava-labs/avalanchego/vms/rpcchainvm/grpcutils"
)

The gci config I'm using:

  gci:
    sections:
      - standard
      - default
      - blank
      - dot
      - prefix(github.com/ava-labs/avalanchego)
    skip-generated: true
    custom-order: true
daixiang0 commented 1 year ago

@dhrubabasu the alias group may be like dot/blank group, if interested, you can try to implement it.

RyoKusnadi commented 1 year ago

Hihi @dhrubabasu i have added the feature. cc: @daixiang0 i think we can close this issue

dhrubabasu commented 1 year ago

Works as expected, thank you so much @RyoKusnadi and @daixiang0

Eagerly waiting for this to be included in golangci-lint 😄

dhrubabasu commented 11 months ago

@daixiang0 Could you cut a release with this included?

daixiang0 commented 11 months ago

Sure.