Skip to content

Commit c60aaca

Browse files
committed
feat: update go-exhaustruct to v2 and adapt to API changes
1 parent 76de562 commit c60aaca

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
lines changed

Diff for: .golangci.example.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ linters-settings:
290290
# If this list is empty, all structs are tested.
291291
include:
292292
- '.*\.Test'
293-
- 'example\.com/package\.ExampleStruct'
293+
- 'example\.com/package\.ExampleStruct[\d]{1,2}'
294294
# List of regular expressions to exclude struct packages and names from check.
295295
exclude:
296296
- 'cobra\.Command$'

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/Antonboom/nilnil v0.1.0
99
github.com/BurntSushi/toml v1.0.0
1010
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24
11-
github.com/GaijinEntertainment/go-exhaustruct v1.0.0
11+
github.com/GaijinEntertainment/go-exhaustruct/v2 v2.0.1
1212
github.com/OpenPeeDeeP/depguard v1.1.0
1313
github.com/alexkohler/prealloc v1.0.0
1414
github.com/ashanbrown/forbidigo v1.3.0

Diff for: go.sum

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/golinters/exhaustruct.go

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,23 @@
11
package golinters
22

33
import (
4-
"strings"
5-
6-
"github.com/GaijinEntertainment/go-exhaustruct/pkg/analyzer"
4+
"github.com/GaijinEntertainment/go-exhaustruct/v2/pkg/analyzer"
75
"golang.org/x/tools/go/analysis"
86

97
"github.com/golangci/golangci-lint/pkg/config"
108
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
119
)
1210

1311
func NewExhaustruct(settings *config.ExhaustructSettings) *goanalysis.Linter {
14-
a := analyzer.Analyzer
12+
include, exclude := []string{}, []string{}
1513

16-
var cfg map[string]map[string]interface{}
1714
if settings != nil {
18-
cfg = map[string]map[string]interface{}{
19-
a.Name: {
20-
"include": strings.Join(settings.Include, ","),
21-
"exclude": strings.Join(settings.Exclude, ","),
22-
},
23-
}
15+
include = settings.Include
16+
exclude = settings.Exclude
2417
}
2518

26-
return goanalysis.NewLinter(
27-
a.Name,
28-
a.Doc,
29-
[]*analysis.Analyzer{a},
30-
cfg,
31-
).WithLoadMode(goanalysis.LoadModeTypesInfo)
19+
a := analyzer.MustNewAnalyzer(include, exclude)
20+
21+
return goanalysis.NewLinter(a.Name, a.Doc, []*analysis.Analyzer{a}, nil).
22+
WithLoadMode(goanalysis.LoadModeTypesInfo)
3223
}

Diff for: test/testdata/configs/exhaustruct.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
linters-settings:
22
exhaustruct:
3-
include: ".*\\.ExhaustructCustom$"
4-
exclude: ".*\\.ExhaustructCustom2"
3+
include:
4+
- .*\.ExhaustructCustom
5+
exclude:
6+
- .*\.ExhaustructCustom[\d]{1,2}

0 commit comments

Comments
 (0)