Skip to content

Commit

Permalink
logcheck: support new golangci-lint plugin interface
Browse files Browse the repository at this point in the history
The new plugin interface was added in golangci/golangci-lint#3887
to allow settings for custom plugins. This commit implements the new
plugin interface with `config` value in the settings, and passes it
to flag `--config`.
  • Loading branch information
linxiulei committed Jul 30, 2023
1 parent 37c27f0 commit e06a80c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -3,6 +3,7 @@ module sigs.k8s.io/logtools
go 1.15

require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
golang.org/x/exp v0.0.0-20210220032938-85be41e4509f
golang.org/x/tools v0.1.12
)
2 changes: 2 additions & 0 deletions go.sum
@@ -1,6 +1,8 @@
dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down
24 changes: 24 additions & 0 deletions logcheck/plugin/plugin.go
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
package main

import (
"github.com/mitchellh/mapstructure"
"golang.org/x/tools/go/analysis"
"sigs.k8s.io/logtools/logcheck/pkg"
)
Expand All @@ -33,3 +34,26 @@ func (*analyzerPlugin) GetAnalyzers() []*analysis.Analyzer {

// AnalyzerPlugin is the entry point for golangci-lint.
var AnalyzerPlugin analyzerPlugin

// Settings is the value struct passed by golangci-lint.
type Settings struct {
Config string
}

// New is the entry point for golangci-lint, which takes priority over AnalyzerPlugin.
func New(conf interface{}) ([]*analysis.Analyzer, error) {
a := pkg.Analyser()

settings := Settings{}
if err := mapstructure.Decode(conf, &settings); err != nil {
return nil, err
}

if settings.Config != "" {
if err := a.Flags.Set("config", settings.Config); err != nil {
return nil, err
}
}

return []*analysis.Analyzer{a}, nil
}

0 comments on commit e06a80c

Please sign in to comment.