aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/golangci/plugin-module-register/register
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2024-04-02 14:37:40 +0000
committerTaras Madan <tarasmadan@google.com>2024-04-03 09:59:40 +0000
commit9d2a90af8850a414d2da20b806d7aa8fd9a297ae (patch)
treeb6ce5a1bc2ecaed9f94b06b36eca20b98929970c /vendor/github.com/golangci/plugin-module-register/register
parentb90978ba49e3321a2d1cd77c07c196b088c97386 (diff)
mod: bump github.com/golangci/golangci-lint from 1.56.2 to 1.57.2
Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.56.2 to 1.57.2. - [Release notes](https://github.com/golangci/golangci-lint/releases) - [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md) - [Commits](https://github.com/golangci/golangci-lint/compare/v1.56.2...v1.57.2) --- updated-dependencies: - dependency-name: github.com/golangci/golangci-lint dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
Diffstat (limited to 'vendor/github.com/golangci/plugin-module-register/register')
-rw-r--r--vendor/github.com/golangci/plugin-module-register/register/register.go73
1 files changed, 73 insertions, 0 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
new file mode 100644
index 000000000..72ad7f46f
--- /dev/null
+++ b/vendor/github.com/golangci/plugin-module-register/register/register.go
@@ -0,0 +1,73 @@
+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
+}