Skip to content

Commit

Permalink
gci: improve error message (#3777)
Browse files Browse the repository at this point in the history
  • Loading branch information
deathbots committed Apr 21, 2023
1 parent 52edd01 commit 842abcd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
9 changes: 7 additions & 2 deletions pkg/golinters/gci.go
Expand Up @@ -2,7 +2,6 @@ package golinters

import (
"fmt"
"strings"
"sync"

gcicfg "github.com/daixiang0/gci/pkg/config"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/testdata/configs/gci.yml
Expand Up @@ -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
4 changes: 4 additions & 0 deletions test/testdata/fix/in/gci.go
Expand Up @@ -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{}
}
6 changes: 4 additions & 2 deletions test/testdata/fix/out/gci.go
Expand Up @@ -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 changes: 6 additions & 5 deletions test/testdata/gci.go
Expand Up @@ -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{}
}

0 comments on commit 842abcd

Please sign in to comment.