GithubHelp home page GithubHelp logo

Comments (20)

twmb avatar twmb commented on September 26, 2024 1

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.

from gci.

daixiang0 avatar daixiang0 commented on September 26, 2024 1

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.

from gci.

daixiang0 avatar daixiang0 commented on September 26, 2024 1

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.

from gci.

StephenBrown2 avatar StephenBrown2 commented on September 26, 2024 1

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.

from gci.

daixiang0 avatar daixiang0 commented on September 26, 2024

Yes, v0.4.0 introduces breaking changes.

from gci.

Dreamacro avatar Dreamacro commented on September 26, 2024

@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.

from gci.

daixiang0 avatar daixiang0 commented on September 26, 2024

The order is not related to your config :(

Please check doc

from gci.

ImSingee avatar ImSingee commented on September 26, 2024

Is there any necessary reason for this breaking change?

from gci.

Dreamacro avatar Dreamacro commented on September 26, 2024

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

from gci.

daixiang0 avatar daixiang0 commented on September 26, 2024

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

Thanks for your input.

from gci.

daixiang0 avatar daixiang0 commented on September 26, 2024

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

from gci.

Dreamacro avatar Dreamacro commented on September 26, 2024

@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.

from gci.

daixiang0 avatar daixiang0 commented on September 26, 2024

@Dreamacro let me confirm it.

from gci.

daixiang0 avatar daixiang0 commented on September 26, 2024

For order config support, tracked as #74.

Close it by #72

from gci.

twmb avatar twmb commented on September 26, 2024

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

from gci.

daixiang0 avatar daixiang0 commented on September 26, 2024

@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.

from gci.

Dreamacro avatar Dreamacro commented on September 26, 2024

@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.

from gci.

daixiang0 avatar daixiang0 commented on September 26, 2024

@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

from gci.

Dreamacro avatar Dreamacro commented on September 26, 2024

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

from gci.

Dreamacro avatar Dreamacro commented on September 26, 2024

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"
)

from gci.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.