Skip to content

Commit 842abcd

Browse files
authored
gci: improve error message (#3777)
1 parent 52edd01 commit 842abcd

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

pkg/golinters/gci.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package golinters
22

33
import (
44
"fmt"
5-
"strings"
65
"sync"
76

87
gcicfg "github.com/daixiang0/gci/pkg/config"
@@ -145,7 +144,13 @@ func getErrorTextForGci(settings config.GciSettings) string {
145144
}
146145

147146
if len(settings.Sections) > 0 {
148-
text += " -s " + strings.Join(settings.Sections, ",")
147+
for _, section := range settings.Sections {
148+
text += " -s " + section
149+
}
150+
}
151+
152+
if settings.CustomOrder {
153+
text += " --custom-order"
149154
}
150155

151156
return text

test/testdata/configs/gci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ linters-settings:
22
gci:
33
sections:
44
- standard
5-
- prefix(github.com/golangci/golangci-lint)
5+
- prefix(github.com/golangci/golangci-lint,github.com/daixiang0/gci)
66
- default
7+
custom-order: true

test/testdata/fix/in/gci.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ package gci
66
import (
77
"github.com/golangci/golangci-lint/pkg/config"
88
"golang.org/x/tools/go/analysis"
9+
910
"fmt"
11+
12+
gcicfg "github.com/daixiang0/gci/pkg/config"
1013
)
1114

1215
func GoimportsLocalTest() {
1316
fmt.Print("x")
1417
_ = config.Config{}
1518
_ = analysis.Analyzer{}
19+
_ = gcicfg.BoolConfig{}
1620
}

test/testdata/fix/out/gci.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ package gci
66
import (
77
"fmt"
88

9-
"golang.org/x/tools/go/analysis"
10-
9+
gcicfg "github.com/daixiang0/gci/pkg/config"
1110
"github.com/golangci/golangci-lint/pkg/config"
11+
12+
"golang.org/x/tools/go/analysis"
1213
)
1314

1415
func GoimportsLocalTest() {
1516
fmt.Print("x")
1617
_ = config.Config{}
1718
_ = analysis.Analyzer{}
19+
_ = gcicfg.BoolConfig{}
1820
}

test/testdata/gci.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
package testdata
44

55
import (
6+
"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"
7+
"github.com/golangci/golangci-lint/pkg/config"
68
"fmt"
7-
8-
"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"
9-
10-
"golang.org/x/tools/go/analysis" // want "File is not \\`gci\\`-ed with --skip-generated -s standard,prefix\\(github.com/golangci/golangci-lint\\),default"
9+
"errors"
10+
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"
1111
)
1212

1313
func GoimportsLocalTest() {
14-
fmt.Print("x")
14+
fmt.Print(errors.New("x"))
1515
_ = config.Config{}
1616
_ = analysis.Analyzer{}
17+
_ = gcicfg.BoolConfig{}
1718
}

0 commit comments

Comments
 (0)