gci: improve error message (#3777)

This commit is contained in:
Rory Prendergast 2023-04-21 13:22:54 -07:00 committed by GitHub
parent 52edd01248
commit 842abcde73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 10 deletions

View File

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

View File

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

View File

@ -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{}
}

View File

@ -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{}
}

11
test/testdata/gci.go vendored
View File

@ -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{}
}