Comments (20)
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.
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.
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.
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.
Yes, v0.4.0 introduces breaking changes.
from gci.
@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.
The order is not related to your config :(
Please check doc
from gci.
Is there any necessary reason for this breaking change?
from gci.
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.
The default ordering will be revert as #72 @twmb @ImSingee
Thanks for your input.
from gci.
@Dreamacro please try golangci/golangci-lint@5e18365
from gci.
@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.
@Dreamacro let me confirm it.
from gci.
For order config support, tracked as #74.
Close it by #72
from gci.
Thank you @daixiang0,
I didn't realize the order wasn't controllable before because I had always ordered custom last.
from gci.
@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.
@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 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: truethen 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.
@daixiang0 Still a bit confused, is this any different from the example in https://github.com/daixiang0/gci#examples?
from gci.
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)
- `gci --version` of v0.10.1 is 0.10.0
- Please stop changing launcher interface HOT 4
- Error when running gci against code with "\r\n" HOT 2
- "C" package causes `gci` to output invalid suggestion HOT 5
- Error: 4:20: expected ';', found "math/big" HOT 3
- Bug: Prefix should ignore space
- Support all stdlib packages (Fix: Infinite repair loop) HOT 5
- Feature Request: treating aliased imports separately HOT 5
- v0.12.0 still claiming to be v0.11.2 HOT 1
- math/rand/v2 not considered as standard library HOT 4
- invalid version: malformed tag HOT 1
- Cannot run GCI with -s localmodule flag HOT 6
- Rework module detection for golangci-lint integration HOT 9
- Something wrong with version 0.13.2 HOT 2
- Multiple prefix() sections should not be automatically sorted HOT 5
- Make the Github "About" for the project grammatically correct
- New std lib `unique`,`iter` in go1.23 can not be recognized HOT 5
- gci error format go file with windows line separator
- vscode integration? HOT 4
- Your `.golangci.yml` has unrecognized field names. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gci.