Skip to content

gci: fix section parsing #5407

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

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pkg/goformatters/gci/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/daixiang0/gci/pkg/config"
"github.com/daixiang0/gci/pkg/section"
sectioni "github.com/golangci/golangci-lint/pkg/goformatters/gci/internal/section"
)

var defaultOrder = map[string]int{
Expand Down Expand Up @@ -39,12 +40,12 @@ type YamlConfig struct {
func (g YamlConfig) Parse() (*Config, error) {
var err error

sections, err := section.Parse(g.SectionStrings)
sections, err := sectioni.Parse(g.SectionStrings)
if err != nil {
return nil, err
}
if sections == nil {
sections = section.DefaultSections()
sections = sectioni.DefaultSections()
}
if err := configureSections(sections, g.ModPath); err != nil {
return nil, err
Expand All @@ -63,7 +64,7 @@ func (g YamlConfig) Parse() (*Config, error) {
})
}

sectionSeparators, err := section.Parse(g.SectionSeparatorStrings)
sectionSeparators, err := sectioni.Parse(g.SectionSeparatorStrings)
if err != nil {
return nil, err
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/goformatters/gci/internal/section/section.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package section

import "github.com/daixiang0/gci/pkg/section"

func DefaultSections() section.SectionList {
return section.SectionList{Standard{}, section.Default{}}
}
16 changes: 16 additions & 0 deletions pkg/golinters/gci/testdata/gci_go124.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build go1.24

//golangcitest:args -Egci
//golangcitest:expected_exitcode 0
package testdata

import (
"crypto/sha3"
"errors"
"fmt"
)

func _() {
fmt.Print(errors.New("x"))
sha3.New224()
}
Loading