Skip to content

Commit

Permalink
gci: fix section parsing (#5407)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Feb 12, 2025
1 parent 5984eab commit 04aec4f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
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()
}

0 comments on commit 04aec4f

Please sign in to comment.