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

bug: v0.4.0 changes default ordering #71

Closed
twmb opened this issue Jul 8, 2022 · 20 comments
Closed

bug: v0.4.0 changes default ordering #71

twmb opened this issue Jul 8, 2022 · 20 comments

Comments

@twmb
Copy link

twmb commented Jul 8, 2022

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

@daixiang0
Copy link
Owner

Yes, v0.4.0 introduces breaking changes.

@twmb
Copy link
Author

twmb commented Jul 9, 2022

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.

@daixiang0
Copy link
Owner

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.

@Dreamacro
Copy link
Contributor

@daixiang0 I have installed the latest golangci-lint (ed4befe), but the auto-fix result is wrong.

linters-settings:
  gci:
    sections:
      - standard
      - default
      - prefix(myorg)

the order of sections has no effect on the result. it makes the code become

  • standard
  • prefix(myorg)
  • default

I confirmed that the prefix is working because when I commented it out, it was merged into default.

@daixiang0
Copy link
Owner

The order is not related to your config :(

Please check doc

@ImSingee
Copy link
Contributor

ImSingee commented Jul 11, 2022

Is there any necessary reason for this breaking change?

@Dreamacro
Copy link
Contributor

Dreamacro commented Jul 11, 2022

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

@daixiang0
Copy link
Owner

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.

@daixiang0
Copy link
Owner

The default ordering will be revert as #72 @twmb @ImSingee

Thanks for your input.

@daixiang0
Copy link
Owner

@Dreamacro please try golangci/golangci-lint@5e18365

@Dreamacro
Copy link
Contributor

@daixiang0 It seems that if the prefix contains uppercase letters, the packets are not aggregated properly.

BTW, It would be nice to be able to sort in the order of sections. Anyway, thanks for your work.

@daixiang0
Copy link
Owner

daixiang0 commented Jul 12, 2022

@Dreamacro let me confirm it.

@StephenBrown2
Copy link

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.

@daixiang0
Copy link
Owner

For order config support, tracked as #74.

Close it by #72

@twmb
Copy link
Author

twmb commented Jul 14, 2022

Thank you @daixiang0,
I didn't realize the order wasn't controllable before because I had always ordered custom last.

@daixiang0
Copy link
Owner

@Dreamacro not reproduce it, could you provide config and codes?

It seems that if the prefix contains uppercase letters, the packets are not aggregated properly.

@Dreamacro
Copy link
Contributor

@daixiang0 It can be reproduced on my repo: https://github.com/Dreamacro/clash

run go install github.com/golangci/golangci-lint/cmd/golangci-lint@master and add this on .golangci.yaml

issues:
  fix: true

then run make lint and all not standard packages will group into one.

@daixiang0
Copy link
Owner

@daixiang0 It can be reproduced on my repo: https://github.com/Dreamacro/clash

run go install github.com/golangci/golangci-lint/cmd/golangci-lint@master and add this on .golangci.yaml

issues:
  fix: true

then run make lint and all not standard packages will group into one.

The default section means:

default: All rest import blocks

So it works as your config.

From https://github.com/daixiang0/gci#gci

@Dreamacro
Copy link
Contributor

@daixiang0 Still a bit confused, is this any different from the example in https://github.com/daixiang0/gci#examples?

@Dreamacro
Copy link
Contributor

Dreamacro commented Jul 14, 2022

I tried the example.

  • When the package has no uppercase characters

gci write -s standard -s default -s "prefix(github.com/daixiang0/gci)" main.go

package main

import (
	"golang.org/x/tools"

	"fmt"

	"github.com/daixiang0/gci"
)

to

package main

import (
	"fmt"

	"golang.org/x/tools"

	"github.com/daixiang0/gci"
)
  • When the package has uppercase characters

gci write -s standard -s default -s "prefix(github.com/Daixiang0/gci)" main.go

package main

import (
	"golang.org/x/tools"

	"fmt"

	"github.com/Daixiang0/gci"
)

to

package main

import (
	"fmt"

	"github.com/Daixiang0/gci"
	"golang.org/x/tools"
)

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

No branches or pull requests

5 participants