gci: bug: v0.4.0 changes default ordering

https://github.com/daixiang0/gci/pull/70/files#r917027845

The already-good code changed from standard, default, prefix(github.com/daixiang0/gci) to standard, prefix(github.com/daixiang0/gci), default even though the sections configuration did not change: https://github.com/daixiang0/gci/blob/9349c88f1609b0e71ec5cac5576b1a413ac25869/pkg/gci/internal/testdata/common.cfg.yaml

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 20 (17 by maintainers)

Most upvoted comments

It would be nice to be able to sort in the order of sections.

I would like to second this. This is the main reason I started using gci, as it states in the README:

The desired output format is highly configurable and allows for more custom formatting than goimport does.

I had been using gci under the assumption that I could also control the order of the import blocks with the order of section flags, and had been configuring it as such, exactly how twmb said.

It looks like sections is just sorting without an order relationship. So sad, I had to look for some other sort of linter 😢

UPDATE

When I install the pre-master golangci-lint go install github.com/golangci/golangci-lint/cmd/golangci-lint@1d8a15a

The order of sections will be sorted according to the expected results

There would be a misunderstanding that I never say the section order can be configured, I will update the document to make it clear.

Now the imports like:

  • standard
  • custom
  • default

The custom section is for your own org, the reason is based on how far the imports are from your repo. The ā€œstandardā€ is built-in, which should be first. The default section means all 3rd-party imports, should be last.

If I’m understanding it correctly, you’re saying that it’s no longer an option to organize custom imports after default?

My organization previously was:

  • stdlib
  • default
  • org, non-repo
  • org, repo

That’s my only use case, and the one use case I see consistently across other repos and orgs, and have used for years.