aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/jgautheron/goconst/api.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2021-02-22 20:37:25 +0100
committerDmitry Vyukov <dvyukov@google.com>2021-02-22 21:02:12 +0100
commitfcc6d71be2c3ce7d9305c04fc2e87af554571bac (patch)
treeb01dbb3d1e2988e28ea158d2d543d603ec0b9569 /vendor/github.com/jgautheron/goconst/api.go
parent8f23c528ad5a943b9ffec5dcaf332fd0f614006e (diff)
go.mod: update golangci-lint to v1.37
Diffstat (limited to 'vendor/github.com/jgautheron/goconst/api.go')
-rw-r--r--vendor/github.com/jgautheron/goconst/api.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/vendor/github.com/jgautheron/goconst/api.go b/vendor/github.com/jgautheron/goconst/api.go
new file mode 100644
index 000000000..e58894bc4
--- /dev/null
+++ b/vendor/github.com/jgautheron/goconst/api.go
@@ -0,0 +1,67 @@
+package goconst
+
+import (
+ "go/ast"
+ "go/token"
+)
+
+type Issue struct {
+ Pos token.Position
+ OccurrencesCount int
+ Str string
+ MatchingConst string
+}
+
+type Config struct {
+ MatchWithConstants bool
+ MinStringLength int
+ MinOccurrences int
+ ParseNumbers bool
+ NumberMin int
+ NumberMax int
+ ExcludeTypes map[Type]bool
+}
+
+func Run(files []*ast.File, fset *token.FileSet, cfg *Config) ([]Issue, error) {
+ p := New(
+ "",
+ "",
+ false,
+ cfg.MatchWithConstants,
+ cfg.ParseNumbers,
+ cfg.NumberMin,
+ cfg.NumberMax,
+ cfg.MinStringLength,
+ cfg.MinOccurrences,
+ cfg.ExcludeTypes,
+ )
+ var issues []Issue
+ for _, f := range files {
+ ast.Walk(&treeVisitor{
+ fileSet: fset,
+ packageName: "",
+ fileName: "",
+ p: p,
+ }, f)
+ }
+ p.ProcessResults()
+
+ for str, item := range p.strs {
+ fi := item[0]
+ i := Issue{
+ Pos: fi.Position,
+ OccurrencesCount: len(item),
+ Str: str,
+ }
+
+ if len(p.consts) != 0 {
+ if cst, ok := p.consts[str]; ok {
+ // const should be in the same package and exported
+ i.MatchingConst = cst.Name
+ }
+ }
+ issues = append(issues, i)
+ }
+
+ return issues, nil
+}