diff options
| author | Taras Madan <tarasmadan@google.com> | 2025-01-22 16:07:17 +0100 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2025-01-23 10:42:36 +0000 |
| commit | 7b4377ad9d8a7205416df8d6217ef2b010f89481 (patch) | |
| tree | e6fec4fd12ff807a16d847923f501075bf71d16c /vendor/github.com/golangci/plugin-module-register/register | |
| parent | 475a4c203afb8b7d3af51c4fd32bb170ff32a45e (diff) | |
vendor: delete
Diffstat (limited to 'vendor/github.com/golangci/plugin-module-register/register')
| -rw-r--r-- | vendor/github.com/golangci/plugin-module-register/register/register.go | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/vendor/github.com/golangci/plugin-module-register/register/register.go b/vendor/github.com/golangci/plugin-module-register/register/register.go deleted file mode 100644 index 72ad7f46f..000000000 --- a/vendor/github.com/golangci/plugin-module-register/register/register.go +++ /dev/null @@ -1,73 +0,0 @@ -package register - -import ( - "bytes" - "encoding/json" - "fmt" - "sync" - - "golang.org/x/tools/go/analysis" -) - -// Plugins load mode. -const ( - LoadModeSyntax = "syntax" - LoadModeTypesInfo = "typesinfo" -) - -var ( - pluginsMu sync.RWMutex - plugins = make(map[string]NewPlugin) -) - -// LinterPlugin the interface of the plugin structure. -type LinterPlugin interface { - BuildAnalyzers() ([]*analysis.Analyzer, error) - GetLoadMode() string -} - -// NewPlugin the contract of the constructor of a plugin. -type NewPlugin func(conf any) (LinterPlugin, error) - -// Plugin registers a plugin. -func Plugin(name string, p NewPlugin) { - pluginsMu.Lock() - - plugins[name] = p - - pluginsMu.Unlock() -} - -// GetPlugin gets a plugin by name. -func GetPlugin(name string) (NewPlugin, error) { - pluginsMu.Lock() - defer pluginsMu.Unlock() - - p, ok := plugins[name] - if !ok { - return nil, fmt.Errorf("plugin %q not found", name) - } - - return p, nil -} - -// DecodeSettings decode settings from golangci-lint to the structure of the plugin configuration. -func DecodeSettings[T any](rawSettings any) (T, error) { - var buffer bytes.Buffer - - if err := json.NewEncoder(&buffer).Encode(rawSettings); err != nil { - var zero T - return zero, fmt.Errorf("encoding settings: %w", err) - } - - decoder := json.NewDecoder(&buffer) - decoder.DisallowUnknownFields() - - s := new(T) - if err := decoder.Decode(s); err != nil { - var zero T - return zero, fmt.Errorf("decoding settings: %w", err) - } - - return *s, nil -} |
