From 8bb683463faca1f31ff8e9da35211456e0f26d03 Mon Sep 17 00:00:00 2001 From: Rory Prendergast Date: Thu, 13 Apr 2023 11:21:10 -0700 Subject: [PATCH] fix(gci): Custom section ordering, new section flags Adds custom-order flag Supports gci StringArray breaking change introduced in version 0.10.0. CSV-style `-s one,two,three` must now be `use -s one -s two -s three` which now supports multiple prefixes. Fixes #3776 --- pkg/golinters/gci.go | 9 +++++++-- test/testdata/configs/gci.yml | 3 ++- test/testdata/fix/in/gci.go | 4 ++++ test/testdata/fix/out/gci.go | 6 ++++-- test/testdata/gci.go | 11 ++++++----- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/pkg/golinters/gci.go b/pkg/golinters/gci.go index 2206ca6af775..4eb26dbdfceb 100644 --- a/pkg/golinters/gci.go +++ b/pkg/golinters/gci.go @@ -2,7 +2,6 @@ package golinters import ( "fmt" - "strings" "sync" gcicfg "github.com/daixiang0/gci/pkg/config" @@ -145,7 +144,13 @@ func getErrorTextForGci(settings config.GciSettings) string { } if len(settings.Sections) > 0 { - text += " -s " + strings.Join(settings.Sections, ",") + for _, section := range settings.Sections { + text += " -s " + section + } + } + + if settings.CustomOrder { + text += " --custom-order" } return text diff --git a/test/testdata/configs/gci.yml b/test/testdata/configs/gci.yml index 487e26383697..3291610acc8b 100644 --- a/test/testdata/configs/gci.yml +++ b/test/testdata/configs/gci.yml @@ -2,5 +2,6 @@ linters-settings: gci: sections: - standard - - prefix(github.com/golangci/golangci-lint) + - prefix(github.com/golangci/golangci-lint,github.com/daixiang0/gci) - default + custom-order: true diff --git a/test/testdata/fix/in/gci.go b/test/testdata/fix/in/gci.go index 4463b6cadb0b..6fd16389f769 100644 --- a/test/testdata/fix/in/gci.go +++ b/test/testdata/fix/in/gci.go @@ -6,11 +6,15 @@ package gci import ( "github.com/golangci/golangci-lint/pkg/config" "golang.org/x/tools/go/analysis" + "fmt" + + gcicfg "github.com/daixiang0/gci/pkg/config" ) func GoimportsLocalTest() { fmt.Print("x") _ = config.Config{} _ = analysis.Analyzer{} + _ = gcicfg.BoolConfig{} } diff --git a/test/testdata/fix/out/gci.go b/test/testdata/fix/out/gci.go index 8e36e66b53ef..0f1fc812f7f9 100644 --- a/test/testdata/fix/out/gci.go +++ b/test/testdata/fix/out/gci.go @@ -6,13 +6,15 @@ package gci import ( "fmt" - "golang.org/x/tools/go/analysis" - + gcicfg "github.com/daixiang0/gci/pkg/config" "github.com/golangci/golangci-lint/pkg/config" + + "golang.org/x/tools/go/analysis" ) func GoimportsLocalTest() { fmt.Print("x") _ = config.Config{} _ = analysis.Analyzer{} + _ = gcicfg.BoolConfig{} } diff --git a/test/testdata/gci.go b/test/testdata/gci.go index db2e33103256..cf0b7dea3693 100644 --- a/test/testdata/gci.go +++ b/test/testdata/gci.go @@ -3,15 +3,16 @@ package testdata import ( + "golang.org/x/tools/go/analysis" // want "File is not \\`gci\\`-ed with --skip-generated -s standard -s prefix\\(github.com/golangci/golangci-lint,github.com/daixiang0/gci\\) -s default --custom-order" + "github.com/golangci/golangci-lint/pkg/config" "fmt" - - "github.com/golangci/golangci-lint/pkg/config" // want "File is not \\`gci\\`-ed with --skip-generated -s standard,prefix\\(github.com/golangci/golangci-lint\\),default" - - "golang.org/x/tools/go/analysis" // want "File is not \\`gci\\`-ed with --skip-generated -s standard,prefix\\(github.com/golangci/golangci-lint\\),default" + "errors" + gcicfg "github.com/daixiang0/gci/pkg/config" // want "File is not \\`gci\\`-ed with --skip-generated -s standard -s prefix\\(github.com/golangci/golangci-lint,github.com/daixiang0/gci\\) -s default --custom-order" ) func GoimportsLocalTest() { - fmt.Print("x") + fmt.Print(errors.New("x")) _ = config.Config{} _ = analysis.Analyzer{} + _ = gcicfg.BoolConfig{} }