forked from kubernetes-sigs/kube-api-linter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.go
More file actions
55 lines (44 loc) · 1.59 KB
/
plugin.go
File metadata and controls
55 lines (44 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package kal
import (
"fmt"
kalanalysis "github.com/JoelSpeed/kal/pkg/analysis"
"github.com/JoelSpeed/kal/pkg/config"
"github.com/JoelSpeed/kal/pkg/validation"
"github.com/golangci/plugin-module-register/register"
"golang.org/x/tools/go/analysis"
"k8s.io/apimachinery/pkg/util/validation/field"
)
func init() {
register.Plugin("kal", New)
}
// New creates a new golangci-lint plugin based on the KAL analyzers.
func New(settings any) (register.LinterPlugin, error) {
s, err := register.DecodeSettings[config.GolangCIConfig](settings)
if err != nil {
return nil, fmt.Errorf("error decoding settings: %w", err)
}
return &GolangCIPlugin{config: s}, nil
}
// GolangCIPlugin constructs a new plugin for the golangci-lint
// plugin pattern.
// This allows golangci-lint to build a version of itself, containing
// all of the anaylzers included in KAL.
type GolangCIPlugin struct {
config config.GolangCIConfig
}
// BuildAnalyzers returns all of the analyzers to run, based on the configuration.
func (f *GolangCIPlugin) BuildAnalyzers() ([]*analysis.Analyzer, error) {
if err := validation.ValidateGolangCIConfig(f.config, field.NewPath("")); err != nil {
return nil, fmt.Errorf("error in KAL configuration: %w", err)
}
registry := kalanalysis.NewRegistry()
analyzers, err := registry.InitializeLinters(f.config.Linters, f.config.LintersConfig)
if err != nil {
return nil, fmt.Errorf("error initializing analyzers: %w", err)
}
return analyzers, nil
}
// GetLoadMode implements the golangci-lint plugin interface.
func (f *GolangCIPlugin) GetLoadMode() string {
return register.LoadModeTypesInfo
}