Skip to content

Commit

Permalink
feat: update go-exhaustruct to v2 and adapt to API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xobotyi committed Apr 10, 2022
1 parent 76de562 commit c60aaca
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ linters-settings:
# If this list is empty, all structs are tested.
include:
- '.*\.Test'
- 'example\.com/package\.ExampleStruct'
- 'example\.com/package\.ExampleStruct[\d]{1,2}'
# List of regular expressions to exclude struct packages and names from check.
exclude:
- 'cobra\.Command$'
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/Antonboom/nilnil v0.1.0
github.com/BurntSushi/toml v1.0.0
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24
github.com/GaijinEntertainment/go-exhaustruct v1.0.0
github.com/GaijinEntertainment/go-exhaustruct/v2 v2.0.1
github.com/OpenPeeDeeP/depguard v1.1.0
github.com/alexkohler/prealloc v1.0.0
github.com/ashanbrown/forbidigo v1.3.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 8 additions & 17 deletions pkg/golinters/exhaustruct.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
package golinters

import (
"strings"

"github.com/GaijinEntertainment/go-exhaustruct/pkg/analyzer"
"github.com/GaijinEntertainment/go-exhaustruct/v2/pkg/analyzer"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

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

var cfg map[string]map[string]interface{}
if settings != nil {
cfg = map[string]map[string]interface{}{
a.Name: {
"include": strings.Join(settings.Include, ","),
"exclude": strings.Join(settings.Exclude, ","),
},
}
include = settings.Include
exclude = settings.Exclude
}

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
cfg,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
a := analyzer.MustNewAnalyzer(include, exclude)

return goanalysis.NewLinter(a.Name, a.Doc, []*analysis.Analyzer{a}, nil).
WithLoadMode(goanalysis.LoadModeTypesInfo)
}
6 changes: 4 additions & 2 deletions test/testdata/configs/exhaustruct.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
linters-settings:
exhaustruct:
include: ".*\\.ExhaustructCustom$"
exclude: ".*\\.ExhaustructCustom2"
include:
- .*\.ExhaustructCustom
exclude:
- .*\.ExhaustructCustom[\d]{1,2}

0 comments on commit c60aaca

Please sign in to comment.