aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/uudashr
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2025-01-22 16:07:17 +0100
committerTaras Madan <tarasmadan@google.com>2025-01-23 10:42:36 +0000
commit7b4377ad9d8a7205416df8d6217ef2b010f89481 (patch)
treee6fec4fd12ff807a16d847923f501075bf71d16c /vendor/github.com/uudashr
parent475a4c203afb8b7d3af51c4fd32bb170ff32a45e (diff)
vendor: delete
Diffstat (limited to 'vendor/github.com/uudashr')
-rw-r--r--vendor/github.com/uudashr/gocognit/LICENSE21
-rw-r--r--vendor/github.com/uudashr/gocognit/README.md228
-rw-r--r--vendor/github.com/uudashr/gocognit/doc.go2
-rw-r--r--vendor/github.com/uudashr/gocognit/gocognit.go399
-rw-r--r--vendor/github.com/uudashr/gocognit/recv.go24
-rw-r--r--vendor/github.com/uudashr/gocognit/recv_pre118.go20
-rw-r--r--vendor/github.com/uudashr/iface/LICENSE201
-rw-r--r--vendor/github.com/uudashr/iface/identical/doc.go3
-rw-r--r--vendor/github.com/uudashr/iface/identical/identical.go138
-rw-r--r--vendor/github.com/uudashr/iface/internal/directive/directive.go76
-rw-r--r--vendor/github.com/uudashr/iface/opaque/doc.go3
-rw-r--r--vendor/github.com/uudashr/iface/opaque/opaque.go326
-rw-r--r--vendor/github.com/uudashr/iface/unused/doc.go3
-rw-r--r--vendor/github.com/uudashr/iface/unused/unused.go138
14 files changed, 0 insertions, 1582 deletions
diff --git a/vendor/github.com/uudashr/gocognit/LICENSE b/vendor/github.com/uudashr/gocognit/LICENSE
deleted file mode 100644
index 75d4b9c98..000000000
--- a/vendor/github.com/uudashr/gocognit/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2019 Nuruddin Ashr
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/vendor/github.com/uudashr/gocognit/README.md b/vendor/github.com/uudashr/gocognit/README.md
deleted file mode 100644
index c15f61bcf..000000000
--- a/vendor/github.com/uudashr/gocognit/README.md
+++ /dev/null
@@ -1,228 +0,0 @@
-[![Go Reference](https://pkg.go.dev/badge/github.com/uudashr/gocognit.svg)](https://pkg.go.dev/github.com/uudashr/gocognit)
-[![go-recipes](https://raw.githubusercontent.com/nikolaydubina/go-recipes/main/badge.svg?raw=true)](https://github.com/nikolaydubina/go-recipes)
-
-# Gocognit
-Gocognit calculates cognitive complexities of functions (and methods) in Go source code. A measurement of how hard does the code is intuitively to understand.
-
-## Understanding the complexity
-
-Given code using `if` statement,
-```go
-func GetWords(number int) string {
- if number == 1 { // +1
- return "one"
- } else if number == 2 { // +1
- return "a couple"
- } else if number == 3 { // +1
- return "a few"
- } else { // +1
- return "lots"
- }
-} // Cognitive complexity = 4
-```
-
-Above code can be refactored using `switch` statement,
-```go
-func GetWords(number int) string {
- switch number { // +1
- case 1:
- return "one"
- case 2:
- return "a couple"
- case 3:
- return "a few"
- default:
- return "lots"
- }
-} // Cognitive complexity = 1
-```
-
-As you see above codes are the same, but the second code are easier to understand, that is why the cognitive complexity score are lower compare to the first one.
-
-## Comparison with cyclomatic complexity
-
-### Example 1
-#### Cyclomatic complexity
-```go
-func GetWords(number int) string { // +1
- switch number {
- case 1: // +1
- return "one"
- case 2: // +1
- return "a couple"
- case 3: // +1
- return "a few"
- default:
- return "lots"
- }
-} // Cyclomatic complexity = 4
-```
-
-#### Cognitive complexity
-```go
-func GetWords(number int) string {
- switch number { // +1
- case 1:
- return "one"
- case 2:
- return "a couple"
- case 3:
- return "a few"
- default:
- return "lots"
- }
-} // Cognitive complexity = 1
-```
-
-Cognitive complexity give lower score compare to cyclomatic complexity.
-
-### Example 2
-#### Cyclomatic complexity
-```go
-func SumOfPrimes(max int) int { // +1
- var total int
-
-OUT:
- for i := 1; i < max; i++ { // +1
- for j := 2; j < i; j++ { // +1
- if i%j == 0 { // +1
- continue OUT
- }
- }
- total += i
- }
-
- return total
-} // Cyclomatic complexity = 4
-```
-
-#### Cognitive complexity
-```go
-func SumOfPrimes(max int) int {
- var total int
-
-OUT:
- for i := 1; i < max; i++ { // +1
- for j := 2; j < i; j++ { // +2 (nesting = 1)
- if i%j == 0 { // +3 (nesting = 2)
- continue OUT // +1
- }
- }
- total += i
- }
-
- return total
-} // Cognitive complexity = 7
-```
-
-Cognitive complexity give higher score compare to cyclomatic complexity.
-
-## Rules
-
-The cognitive complexity of a function is calculated according to the
-following rules:
-> Note: these rules are specific for Go, please see the [original whitepaper](https://www.sonarsource.com/docs/CognitiveComplexity.pdf) for more complete reference.
-
-### Increments
-There is an increment for each of the following:
-1. `if`, `else if`, `else`
-2. `switch`, `select`
-3. `for`
-4. `goto` LABEL, `break` LABEL, `continue` LABEL
-5. sequence of binary logical operators
-6. each method in a recursion cycle
-
-### Nesting level
-The following structures increment the nesting level:
-1. `if`, `else if`, `else`
-2. `switch`, `select`
-3. `for`
-4. function literal or lambda
-
-### Nesting increments
-The following structures receive a nesting increment commensurate with their nested depth inside nesting structures:
-1. `if`
-2. `switch`, `select`
-3. `for`
-
-## Installation
-
-```
-$ go install github.com/uudashr/gocognit/cmd/gocognit@latest
-```
-
-or
-
-```
-$ go get github.com/uudashr/gocognit/cmd/gocognit
-```
-
-## Usage
-
-```
-$ gocognit
-Calculate cognitive complexities of Go functions.
-
-Usage:
-
- gocognit [<flag> ...] <Go file or directory> ...
-
-Flags:
-
- -over N show functions with complexity > N only
- and return exit code 1 if the output is non-empty
- -top N show the top N most complex functions only
- -avg show the average complexity over all functions,
- not depending on whether -over or -top are set
- -json encode the output as JSON
- -f format string the format to use
- (default "{{.PkgName}}.{{.FuncName}}:{{.Complexity}}:{{.Pos}}")
-
-The (default) output fields for each line are:
-
- <complexity> <package> <function> <file:row:column>
-
-The (default) output fields for each line are:
-
- {{.Complexity}} {{.PkgName}} {{.FuncName}} {{.Pos}}
-
-or equal to <complexity> <package> <function> <file:row:column>
-
-The struct being passed to the template is:
-
- type Stat struct {
- PkgName string
- FuncName string
- Complexity int
- Pos token.Position
- }
-```
-
-Examples:
-
-```
-$ gocognit .
-$ gocognit main.go
-$ gocognit -top 10 src/
-$ gocognit -over 25 docker
-$ gocognit -avg .
-$ gocognit -ignore "_test|testdata" .
-```
-
-The output fields for each line are:
-```
-<complexity> <package> <function> <file:row:column>
-```
-
-## Ignore individual functions
-Ignore individual functions by specifying `gocognit:ignore` directive.
-```go
-//gocognit:ignore
-func IgnoreMe() {
- // ...
-}
-```
-
-## Related project
-- [Gocyclo](https://github.com/fzipp/gocyclo) where the code are based on.
-- [Cognitive Complexity: A new way of measuring understandability](https://www.sonarsource.com/docs/CognitiveComplexity.pdf) white paper by G. Ann Campbell.
diff --git a/vendor/github.com/uudashr/gocognit/doc.go b/vendor/github.com/uudashr/gocognit/doc.go
deleted file mode 100644
index ae3d0a226..000000000
--- a/vendor/github.com/uudashr/gocognit/doc.go
+++ /dev/null
@@ -1,2 +0,0 @@
-// Package gocognit defines Analyzer other utilities to checks and calculate the complexity of function based on "cognitive complexity" methods.
-package gocognit
diff --git a/vendor/github.com/uudashr/gocognit/gocognit.go b/vendor/github.com/uudashr/gocognit/gocognit.go
deleted file mode 100644
index 2bba2eb4f..000000000
--- a/vendor/github.com/uudashr/gocognit/gocognit.go
+++ /dev/null
@@ -1,399 +0,0 @@
-package gocognit
-
-import (
- "fmt"
- "go/ast"
- "go/token"
-
- "golang.org/x/tools/go/analysis"
- "golang.org/x/tools/go/analysis/passes/inspect"
- "golang.org/x/tools/go/ast/inspector"
-)
-
-// Stat is statistic of the complexity.
-type Stat struct {
- PkgName string
- FuncName string
- Complexity int
- Pos token.Position
-}
-
-func (s Stat) String() string {
- return fmt.Sprintf("%d %s %s %s", s.Complexity, s.PkgName, s.FuncName, s.Pos)
-}
-
-// ComplexityStats builds the complexity statistics.
-func ComplexityStats(f *ast.File, fset *token.FileSet, stats []Stat) []Stat {
- for _, decl := range f.Decls {
- if fn, ok := decl.(*ast.FuncDecl); ok {
- d := parseDirective(fn.Doc)
- if d.Ignore {
- continue
- }
-
- stats = append(stats, Stat{
- PkgName: f.Name.Name,
- FuncName: funcName(fn),
- Complexity: Complexity(fn),
- Pos: fset.Position(fn.Pos()),
- })
- }
- }
- return stats
-}
-
-type directive struct {
- Ignore bool
-}
-
-func parseDirective(doc *ast.CommentGroup) directive {
- if doc == nil {
- return directive{}
- }
-
- for _, c := range doc.List {
- if c.Text == "//gocognit:ignore" {
- return directive{Ignore: true}
- }
- }
-
- return directive{}
-}
-
-// funcName returns the name representation of a function or method:
-// "(Type).Name" for methods or simply "Name" for functions.
-func funcName(fn *ast.FuncDecl) string {
- if fn.Recv != nil {
- if fn.Recv.NumFields() > 0 {
- typ := fn.Recv.List[0].Type
- return fmt.Sprintf("(%s).%s", recvString(typ), fn.Name)
- }
- }
- return fn.Name.Name
-}
-
-// Complexity calculates the cognitive complexity of a function.
-func Complexity(fn *ast.FuncDecl) int {
- v := complexityVisitor{
- name: fn.Name,
- }
-
- ast.Walk(&v, fn)
- return v.complexity
-}
-
-type complexityVisitor struct {
- name *ast.Ident
- complexity int
- nesting int
- elseNodes map[ast.Node]bool
- calculatedExprs map[ast.Expr]bool
-}
-
-func (v *complexityVisitor) incNesting() {
- v.nesting++
-}
-
-func (v *complexityVisitor) decNesting() {
- v.nesting--
-}
-
-func (v *complexityVisitor) incComplexity() {
- v.complexity++
-}
-
-func (v *complexityVisitor) nestIncComplexity() {
- v.complexity += (v.nesting + 1)
-}
-
-func (v *complexityVisitor) markAsElseNode(n ast.Node) {
- if v.elseNodes == nil {
- v.elseNodes = make(map[ast.Node]bool)
- }
-
- v.elseNodes[n] = true
-}
-
-func (v *complexityVisitor) markedAsElseNode(n ast.Node) bool {
- if v.elseNodes == nil {
- return false
- }
-
- return v.elseNodes[n]
-}
-
-func (v *complexityVisitor) markCalculated(e ast.Expr) {
- if v.calculatedExprs == nil {
- v.calculatedExprs = make(map[ast.Expr]bool)
- }
-
- v.calculatedExprs[e] = true
-}
-
-func (v *complexityVisitor) isCalculated(e ast.Expr) bool {
- if v.calculatedExprs == nil {
- return false
- }
-
- return v.calculatedExprs[e]
-}
-
-// Visit implements the ast.Visitor interface.
-func (v *complexityVisitor) Visit(n ast.Node) ast.Visitor {
- switch n := n.(type) {
- case *ast.IfStmt:
- return v.visitIfStmt(n)
- case *ast.SwitchStmt:
- return v.visitSwitchStmt(n)
- case *ast.TypeSwitchStmt:
- return v.visitTypeSwitchStmt(n)
- case *ast.SelectStmt:
- return v.visitSelectStmt(n)
- case *ast.ForStmt:
- return v.visitForStmt(n)
- case *ast.RangeStmt:
- return v.visitRangeStmt(n)
- case *ast.FuncLit:
- return v.visitFuncLit(n)
- case *ast.BranchStmt:
- return v.visitBranchStmt(n)
- case *ast.BinaryExpr:
- return v.visitBinaryExpr(n)
- case *ast.CallExpr:
- return v.visitCallExpr(n)
- }
- return v
-}
-
-func (v *complexityVisitor) visitIfStmt(n *ast.IfStmt) ast.Visitor {
- v.incIfComplexity(n)
-
- if n := n.Init; n != nil {
- ast.Walk(v, n)
- }
-
- ast.Walk(v, n.Cond)
-
- pure := !v.markedAsElseNode(n) // pure `if` statement, not an `else if`
- if pure {
- v.incNesting()
- ast.Walk(v, n.Body)
- v.decNesting()
- } else {
- ast.Walk(v, n.Body)
- }
-
- if _, ok := n.Else.(*ast.BlockStmt); ok {
- v.incComplexity()
-
- ast.Walk(v, n.Else)
- } else if _, ok := n.Else.(*ast.IfStmt); ok {
- v.markAsElseNode(n.Else)
- ast.Walk(v, n.Else)
- }
-
- return nil
-}
-
-func (v *complexityVisitor) visitSwitchStmt(n *ast.SwitchStmt) ast.Visitor {
- v.nestIncComplexity()
-
- if n := n.Init; n != nil {
- ast.Walk(v, n)
- }
-
- if n := n.Tag; n != nil {
- ast.Walk(v, n)
- }
-
- v.incNesting()
- ast.Walk(v, n.Body)
- v.decNesting()
- return nil
-}
-
-func (v *complexityVisitor) visitTypeSwitchStmt(n *ast.TypeSwitchStmt) ast.Visitor {
- v.nestIncComplexity()
-
- if n := n.Init; n != nil {
- ast.Walk(v, n)
- }
-
- if n := n.Assign; n != nil {
- ast.Walk(v, n)
- }
-
- v.incNesting()
- ast.Walk(v, n.Body)
- v.decNesting()
- return nil
-}
-
-func (v *complexityVisitor) visitSelectStmt(n *ast.SelectStmt) ast.Visitor {
- v.nestIncComplexity()
-
- v.incNesting()
- ast.Walk(v, n.Body)
- v.decNesting()
- return nil
-}
-
-func (v *complexityVisitor) visitForStmt(n *ast.ForStmt) ast.Visitor {
- v.nestIncComplexity()
-
- if n := n.Init; n != nil {
- ast.Walk(v, n)
- }
-
- if n := n.Cond; n != nil {
- ast.Walk(v, n)
- }
-
- if n := n.Post; n != nil {
- ast.Walk(v, n)
- }
-
- v.incNesting()
- ast.Walk(v, n.Body)
- v.decNesting()
- return nil
-}
-
-func (v *complexityVisitor) visitRangeStmt(n *ast.RangeStmt) ast.Visitor {
- v.nestIncComplexity()
-
- if n := n.Key; n != nil {
- ast.Walk(v, n)
- }
-
- if n := n.Value; n != nil {
- ast.Walk(v, n)
- }
-
- ast.Walk(v, n.X)
-
- v.incNesting()
- ast.Walk(v, n.Body)
- v.decNesting()
- return nil
-}
-
-func (v *complexityVisitor) visitFuncLit(n *ast.FuncLit) ast.Visitor {
- ast.Walk(v, n.Type)
-
- v.incNesting()
- ast.Walk(v, n.Body)
- v.decNesting()
- return nil
-}
-
-func (v *complexityVisitor) visitBranchStmt(n *ast.BranchStmt) ast.Visitor {
- if n.Label != nil {
- v.incComplexity()
- }
- return v
-}
-
-func (v *complexityVisitor) visitBinaryExpr(n *ast.BinaryExpr) ast.Visitor {
- if isBinaryLogicalOp(n.Op) && !v.isCalculated(n) {
- ops := v.collectBinaryOps(n)
-
- var lastOp token.Token
- for _, op := range ops {
- if lastOp != op {
- v.incComplexity()
- lastOp = op
- }
- }
- }
- return v
-}
-
-func (v *complexityVisitor) visitCallExpr(n *ast.CallExpr) ast.Visitor {
- if callIdent, ok := n.Fun.(*ast.Ident); ok {
- obj, name := callIdent.Obj, callIdent.Name
- if obj == v.name.Obj && name == v.name.Name {
- // called by same function directly (direct recursion)
- v.incComplexity()
- }
- }
- return v
-}
-
-func (v *complexityVisitor) collectBinaryOps(exp ast.Expr) []token.Token {
- v.markCalculated(exp)
- if exp, ok := exp.(*ast.BinaryExpr); ok {
- return mergeBinaryOps(v.collectBinaryOps(exp.X), exp.Op, v.collectBinaryOps(exp.Y))
- }
- return nil
-}
-
-func (v *complexityVisitor) incIfComplexity(n *ast.IfStmt) {
- if v.markedAsElseNode(n) {
- v.incComplexity()
- } else {
- v.nestIncComplexity()
- }
-}
-
-func mergeBinaryOps(x []token.Token, op token.Token, y []token.Token) []token.Token {
- var out []token.Token
- out = append(out, x...)
- if isBinaryLogicalOp(op) {
- out = append(out, op)
- }
- out = append(out, y...)
- return out
-}
-
-func isBinaryLogicalOp(op token.Token) bool {
- return op == token.LAND || op == token.LOR
-}
-
-const Doc = `Find complex function using cognitive complexity calculation.
-
-The gocognit analysis reports functions or methods which the complexity is over
-than the specified limit.`
-
-// Analyzer reports a diagnostic for every function or method which is
-// too complex specified by its -over flag.
-var Analyzer = &analysis.Analyzer{
- Name: "gocognit",
- Doc: Doc,
- Requires: []*analysis.Analyzer{inspect.Analyzer},
- Run: run,
-}
-
-var (
- over int // -over flag
-)
-
-func init() {
- Analyzer.Flags.IntVar(&over, "over", over, "show functions with complexity > N only")
-}
-
-func run(pass *analysis.Pass) (interface{}, error) {
- inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
-
- nodeFilter := []ast.Node{
- (*ast.FuncDecl)(nil),
- }
- inspect.Preorder(nodeFilter, func(n ast.Node) {
- funcDecl := n.(*ast.FuncDecl)
-
- d := parseDirective(funcDecl.Doc)
- if d.Ignore {
- return
- }
-
- fnName := funcName(funcDecl)
-
- fnComplexity := Complexity(funcDecl)
-
- if fnComplexity > over {
- pass.Reportf(funcDecl.Pos(), "cognitive complexity %d of func %s is high (> %d)", fnComplexity, fnName, over)
- }
- })
-
- return nil, nil
-}
diff --git a/vendor/github.com/uudashr/gocognit/recv.go b/vendor/github.com/uudashr/gocognit/recv.go
deleted file mode 100644
index 2f20d843a..000000000
--- a/vendor/github.com/uudashr/gocognit/recv.go
+++ /dev/null
@@ -1,24 +0,0 @@
-//go:build go1.18
-// +build go1.18
-
-package gocognit
-
-import (
- "go/ast"
-)
-
-// recvString returns a string representation of recv of the
-// form "T", "*T", or "BADRECV" (if not a proper receiver type).
-func recvString(recv ast.Expr) string {
- switch t := recv.(type) {
- case *ast.Ident:
- return t.Name
- case *ast.StarExpr:
- return "*" + recvString(t.X)
- case *ast.IndexExpr:
- return recvString(t.X)
- case *ast.IndexListExpr:
- return recvString(t.X)
- }
- return "BADRECV"
-}
diff --git a/vendor/github.com/uudashr/gocognit/recv_pre118.go b/vendor/github.com/uudashr/gocognit/recv_pre118.go
deleted file mode 100644
index 9e0ebfd82..000000000
--- a/vendor/github.com/uudashr/gocognit/recv_pre118.go
+++ /dev/null
@@ -1,20 +0,0 @@
-//go:build !go1.18
-// +build !go1.18
-
-package gocognit
-
-import (
- "go/ast"
-)
-
-// recvString returns a string representation of recv of the
-// form "T", "*T", or "BADRECV" (if not a proper receiver type).
-func recvString(recv ast.Expr) string {
- switch t := recv.(type) {
- case *ast.Ident:
- return t.Name
- case *ast.StarExpr:
- return "*" + recvString(t.X)
- }
- return "BADRECV"
-}
diff --git a/vendor/github.com/uudashr/iface/LICENSE b/vendor/github.com/uudashr/iface/LICENSE
deleted file mode 100644
index 261eeb9e9..000000000
--- a/vendor/github.com/uudashr/iface/LICENSE
+++ /dev/null
@@ -1,201 +0,0 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
diff --git a/vendor/github.com/uudashr/iface/identical/doc.go b/vendor/github.com/uudashr/iface/identical/doc.go
deleted file mode 100644
index 5b848a913..000000000
--- a/vendor/github.com/uudashr/iface/identical/doc.go
+++ /dev/null
@@ -1,3 +0,0 @@
-// Package identical defines an Analyzer that identifies interfaces in the same
-// package with identical methods or constraints.
-package identical
diff --git a/vendor/github.com/uudashr/iface/identical/identical.go b/vendor/github.com/uudashr/iface/identical/identical.go
deleted file mode 100644
index bd573cfc4..000000000
--- a/vendor/github.com/uudashr/iface/identical/identical.go
+++ /dev/null
@@ -1,138 +0,0 @@
-package identical
-
-import (
- "fmt"
- "go/ast"
- "go/token"
- "go/types"
- "reflect"
-
- "github.com/uudashr/iface/internal/directive"
- "golang.org/x/tools/go/analysis"
- "golang.org/x/tools/go/analysis/passes/inspect"
- "golang.org/x/tools/go/ast/inspector"
-)
-
-// Analyzer is the duplicate interface analyzer.
-var Analyzer = newAnalyzer()
-
-func newAnalyzer() *analysis.Analyzer {
- r := runner{}
-
- analyzer := &analysis.Analyzer{
- Name: "identical",
- Doc: "Identifies interfaces in the same package that have identical method sets",
- URL: "https://pkg.go.dev/github.com/uudashr/iface/duplicate",
- Requires: []*analysis.Analyzer{inspect.Analyzer},
- Run: r.run,
- }
-
- analyzer.Flags.BoolVar(&r.debug, "debug", false, "enable debug mode")
-
- return analyzer
-}
-
-type runner struct {
- debug bool
-}
-
-func (r *runner) run(pass *analysis.Pass) (interface{}, error) {
- inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
-
- // Collect interface type declarations
- ifaceDecls := make(map[string]token.Pos)
- ifaceTypes := make(map[string]*types.Interface)
-
- nodeFilter := []ast.Node{
- (*ast.GenDecl)(nil),
- }
-
- inspect.Preorder(nodeFilter, func(n ast.Node) {
- decl, ok := n.(*ast.GenDecl)
- if !ok {
- return
- }
-
- if r.debug {
- fmt.Printf("GenDecl: %v specs=%d\n", decl.Tok, len(decl.Specs))
- }
-
- if decl.Tok != token.TYPE {
- return
- }
-
- for i, spec := range decl.Specs {
- if r.debug {
- fmt.Printf(" spec[%d]: %v %v\n", i, spec, reflect.TypeOf(spec))
- }
-
- ts, ok := spec.(*ast.TypeSpec)
- if !ok {
- return
- }
-
- ifaceType, ok := ts.Type.(*ast.InterfaceType)
- if !ok {
- return
- }
-
- if r.debug {
- fmt.Println("Interface declaration:", ts.Name.Name, ts.Pos(), len(ifaceType.Methods.List))
-
- for i, field := range ifaceType.Methods.List {
- switch ft := field.Type.(type) {
- case *ast.FuncType:
- fmt.Printf(" [%d] Field: func %s %v %v\n", i, field.Names[0].Name, reflect.TypeOf(field.Type), field.Pos())
- case *ast.Ident:
- fmt.Printf(" [%d] Field: iface %s %v %v\n", i, ft.Name, reflect.TypeOf(field.Type), field.Pos())
- default:
- fmt.Printf(" [%d] Field: unknown %v\n", i, reflect.TypeOf(ft))
- }
- }
- }
-
- dir := directive.ParseIgnore(decl.Doc)
- if dir != nil && dir.ShouldIgnore(pass.Analyzer.Name) {
- // skip due to ignore directive
- continue
- }
-
- ifaceDecls[ts.Name.Name] = ts.Pos()
-
- obj := pass.TypesInfo.Defs[ts.Name]
- if obj == nil {
- return
- }
-
- iface, ok := obj.Type().Underlying().(*types.Interface)
- if !ok {
- return
- }
-
- ifaceTypes[ts.Name.Name] = iface
- }
- })
-
-Loop:
- for name, typ := range ifaceTypes {
- for otherName, otherTyp := range ifaceTypes {
- if name == otherName {
- continue
- }
-
- if !types.Identical(typ, otherTyp) {
- continue
- }
-
- if r.debug {
- fmt.Println("Identical interface:", name, "and", otherName)
- }
-
- pass.Reportf(ifaceDecls[name], "interface %s contains identical methods or type constraints from another interface, causing redundancy", name)
-
- continue Loop
- }
- }
-
- return nil, nil
-}
diff --git a/vendor/github.com/uudashr/iface/internal/directive/directive.go b/vendor/github.com/uudashr/iface/internal/directive/directive.go
deleted file mode 100644
index 05c62928e..000000000
--- a/vendor/github.com/uudashr/iface/internal/directive/directive.go
+++ /dev/null
@@ -1,76 +0,0 @@
-package directive
-
-import (
- "go/ast"
- "slices"
- "strings"
-)
-
-// Ignore represent a special instruction embebded in the source code.
-//
-// The directive can be as simple as
-//
-// //iface:ignore
-//
-// or consist of name
-//
-// //iface:ignore=unused
-//
-// or multiple names
-//
-// //iface:ignore=unused,identical
-type Ignore struct {
- Names []string
-}
-
-// ParseIgnore parse the directive from the comments.
-func ParseIgnore(doc *ast.CommentGroup) *Ignore {
- if doc == nil {
- return nil
- }
-
- for _, comment := range doc.List {
- text := strings.TrimSpace(comment.Text)
- if text == "//iface:ignore" {
- return &Ignore{}
- }
-
- // parse the Names if exists
- if val, found := strings.CutPrefix(text, "//iface:ignore="); found {
- val = strings.TrimSpace(val)
- if val == "" {
- return &Ignore{}
- }
-
- names := strings.Split(val, ",")
- if len(names) == 0 {
- continue
- }
-
- for i, name := range names {
- names[i] = strings.TrimSpace(name)
- }
-
- if len(names) > 0 {
- return &Ignore{Names: names}
- }
-
- return &Ignore{}
- }
- }
-
- return nil
-}
-
-func (i *Ignore) hasName(name string) bool {
- return slices.Contains(i.Names, name)
-}
-
-// ShouldIgnore return true if the name should be ignored.
-func (i *Ignore) ShouldIgnore(name string) bool {
- if len(i.Names) == 0 {
- return true
- }
-
- return i.hasName(name)
-}
diff --git a/vendor/github.com/uudashr/iface/opaque/doc.go b/vendor/github.com/uudashr/iface/opaque/doc.go
deleted file mode 100644
index 1e5a53897..000000000
--- a/vendor/github.com/uudashr/iface/opaque/doc.go
+++ /dev/null
@@ -1,3 +0,0 @@
-// Package opaque defines an Analyzer to that detects interfaces that are used
-// to abstract a single concrete implementation only.
-package opaque
diff --git a/vendor/github.com/uudashr/iface/opaque/opaque.go b/vendor/github.com/uudashr/iface/opaque/opaque.go
deleted file mode 100644
index f8b7bf4c6..000000000
--- a/vendor/github.com/uudashr/iface/opaque/opaque.go
+++ /dev/null
@@ -1,326 +0,0 @@
-package opaque
-
-import (
- "fmt"
- "go/ast"
- "go/types"
- "reflect"
- "strings"
-
- "github.com/uudashr/iface/internal/directive"
- "golang.org/x/tools/go/analysis"
- "golang.org/x/tools/go/analysis/passes/inspect"
- "golang.org/x/tools/go/ast/inspector"
-)
-
-// Analyzer is the opaque interface analyzer.
-var Analyzer = newAnalyzer()
-
-func newAnalyzer() *analysis.Analyzer {
- r := runner{}
-
- analyzer := &analysis.Analyzer{
- Name: "opaque",
- Doc: "Identifies functions that return interfaces, but the actual returned value is always a single concrete implementation.",
- URL: "https://pkg.go.dev/github.com/uudashr/iface/opaque",
- Requires: []*analysis.Analyzer{inspect.Analyzer},
- Run: r.run,
- }
-
- analyzer.Flags.BoolVar(&r.debug, "debug", false, "enable debug mode")
-
- return analyzer
-}
-
-type runner struct {
- debug bool
-}
-
-func (r *runner) run(pass *analysis.Pass) (interface{}, error) {
- inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
-
- // Find function declarations that return an interface
-
- nodeFilter := []ast.Node{
- (*ast.FuncDecl)(nil),
- }
-
- inspect.Preorder(nodeFilter, func(n ast.Node) {
- funcDecl := n.(*ast.FuncDecl)
-
- if funcDecl.Recv != nil {
- // skip methods
- return
- }
-
- if funcDecl.Body == nil {
- // skip functions without body
- return
- }
-
- if funcDecl.Type.Results == nil {
- // skip functions without return values
- return
- }
-
- if r.debug {
- fmt.Printf("Function declaration %s\n", funcDecl.Name.Name)
- fmt.Printf(" Results len=%d\n", len(funcDecl.Type.Results.List))
- }
-
- dir := directive.ParseIgnore(funcDecl.Doc)
- if dir != nil && dir.ShouldIgnore(pass.Analyzer.Name) {
- // skip ignored function
- return
- }
-
- // Pre-check, only function that has interface return type will be processed
- var hasInterfaceReturnType bool
-
- var outCount int
-
- for i, result := range funcDecl.Type.Results.List {
- outInc := 1
- if namesLen := len(result.Names); namesLen > 0 {
- outInc = namesLen
- }
-
- outCount += outInc
-
- resType := result.Type
- typ := pass.TypesInfo.TypeOf(resType)
-
- if r.debug {
- fmt.Printf(" [%d] len=%d %v %v %v | %v %v interface=%t\n", i, len(result.Names), result.Names, resType, reflect.TypeOf(resType), typ, reflect.TypeOf(typ), types.IsInterface(typ))
- }
-
- if types.IsInterface(typ) && !hasInterfaceReturnType {
- hasInterfaceReturnType = true
- }
- }
-
- if r.debug {
- fmt.Printf(" hasInterface=%t outCount=%d\n", hasInterfaceReturnType, outCount)
- }
-
- if !hasInterfaceReturnType {
- // skip, since it has no interface return type
- return
- }
-
- // Collect types on every return statement
- retStmtTypes := make([]map[types.Type]struct{}, outCount)
- for i := range retStmtTypes {
- retStmtTypes[i] = make(map[types.Type]struct{})
- }
-
- ast.Inspect(funcDecl.Body, func(n ast.Node) bool {
- switch n := n.(type) {
- case *ast.FuncLit:
- // ignore nested functions
- return false
- case *ast.ReturnStmt:
- if r.debug {
- fmt.Printf(" Return statements %v len=%d\n", n.Results, len(n.Results))
- }
-
- for i, result := range n.Results {
- if r.debug {
- fmt.Printf(" [%d] %v %v\n", i, result, reflect.TypeOf(result))
- }
-
- switch res := result.(type) {
- case *ast.CallExpr:
- if r.debug {
- fmt.Printf(" CallExpr Fun: %v %v\n", res.Fun, reflect.TypeOf(res.Fun))
- }
-
- typ := pass.TypesInfo.TypeOf(res)
- switch typ := typ.(type) {
- case *types.Tuple:
- for i := range typ.Len() {
- v := typ.At(i)
- vTyp := v.Type()
- retStmtTypes[i][vTyp] = struct{}{}
-
- if r.debug {
- fmt.Printf(" Tuple [%d]: %v %v | %v %v interface=%t\n", i, v, reflect.TypeOf(v), vTyp, reflect.TypeOf(vTyp), types.IsInterface(vTyp))
- }
- }
- default:
- retStmtTypes[i][typ] = struct{}{}
- }
-
- case *ast.Ident:
- if r.debug {
- fmt.Printf(" Ident: %v %v\n", res, reflect.TypeOf(res))
- }
-
- typ := pass.TypesInfo.TypeOf(res)
-
- if r.debug {
- fmt.Printf(" Ident type: %v %v interface=%t\n", typ, reflect.TypeOf(typ), types.IsInterface(typ))
- }
-
- retStmtTypes[i][typ] = struct{}{}
- case *ast.UnaryExpr:
- if r.debug {
- fmt.Printf(" UnaryExpr X: %v \n", res.X)
- }
-
- typ := pass.TypesInfo.TypeOf(res)
-
- if r.debug {
- fmt.Printf(" UnaryExpr type: %v %v interface=%t\n", typ, reflect.TypeOf(typ), types.IsInterface(typ))
- }
-
- retStmtTypes[i][typ] = struct{}{}
- default:
- if r.debug {
- fmt.Printf(" Unknown: %v %v\n", res, reflect.TypeOf(res))
- }
-
- typ := pass.TypesInfo.TypeOf(res)
- retStmtTypes[i][typ] = struct{}{}
- }
- }
-
- return false
- default:
- return true
- }
- })
-
- // Compare func return types with the return statement types
- var nextIdx int
-
- for _, result := range funcDecl.Type.Results.List {
- resType := result.Type
- typ := pass.TypesInfo.TypeOf(resType)
-
- consumeCount := 1
- if len(result.Names) > 0 {
- consumeCount = len(result.Names)
- }
-
- currentIdx := nextIdx
- nextIdx += consumeCount
-
- // Check return type
- if !types.IsInterface(typ) {
- // it is a concrete type
- continue
- }
-
- if typ.String() == "error" {
- // very common case to have return type error
- continue
- }
-
- if !fromSamePackage(pass, typ) {
- // ignore interface from other package
- continue
- }
-
- // Check statement type
- stmtTyps := retStmtTypes[currentIdx]
-
- stmtTypsSize := len(stmtTyps)
- if stmtTypsSize > 1 {
- // it has multiple implementation
- continue
- }
-
- if stmtTypsSize == 0 {
- // function use named return value, while return statement is empty
- continue
- }
-
- var stmtTyp types.Type
- for t := range stmtTyps {
- // expect only one, we don't have to break it
- stmtTyp = t
- }
-
- if types.IsInterface(stmtTyp) {
- // not concrete type, skip
- continue
- }
-
- if r.debug {
- fmt.Printf("stmtType: %v %v | %v %v\n", stmtTyp, reflect.TypeOf(stmtTyp), stmtTyp.Underlying(), reflect.TypeOf(stmtTyp.Underlying()))
- }
-
- switch stmtTyp := stmtTyp.(type) {
- case *types.Basic:
- if stmtTyp.Kind() == types.UntypedNil {
- // ignore nil
- continue
- }
- case *types.Named:
- if _, ok := stmtTyp.Underlying().(*types.Signature); ok {
- // skip function type
- continue
- }
- }
-
- retTypeName := typ.String()
- if fromSamePackage(pass, typ) {
- retTypeName = removePkgPrefix(retTypeName)
- }
-
- stmtTypName := stmtTyp.String()
- if fromSamePackage(pass, stmtTyp) {
- stmtTypName = removePkgPrefix(stmtTypName)
- }
-
- pass.Reportf(result.Pos(),
- "%s function return %s interface at the %s result, abstract a single concrete implementation of %s",
- funcDecl.Name.Name,
- retTypeName,
- positionStr(currentIdx),
- stmtTypName)
- }
- })
-
- return nil, nil
-}
-
-func positionStr(idx int) string {
- switch idx {
- case 0:
- return "1st"
- case 1:
- return "2nd"
- case 2:
- return "3rd"
- default:
- return fmt.Sprintf("%dth", idx+1)
- }
-}
-
-func fromSamePackage(pass *analysis.Pass, typ types.Type) bool {
- switch typ := typ.(type) {
- case *types.Named:
- currentPkg := pass.Pkg
- ifacePkg := typ.Obj().Pkg()
-
- return currentPkg == ifacePkg
- case *types.Pointer:
- return fromSamePackage(pass, typ.Elem())
- default:
- return false
- }
-}
-
-func removePkgPrefix(typeStr string) string {
- if typeStr[0] == '*' {
- return "*" + removePkgPrefix(typeStr[1:])
- }
-
- if lastDot := strings.LastIndex(typeStr, "."); lastDot != -1 {
- return typeStr[lastDot+1:]
- }
-
- return typeStr
-}
diff --git a/vendor/github.com/uudashr/iface/unused/doc.go b/vendor/github.com/uudashr/iface/unused/doc.go
deleted file mode 100644
index d5b6f24bb..000000000
--- a/vendor/github.com/uudashr/iface/unused/doc.go
+++ /dev/null
@@ -1,3 +0,0 @@
-// Package unused defines an Analyzer that indetifies interfaces that are not
-// used anywhere in the same package where the interface is defined.
-package unused
diff --git a/vendor/github.com/uudashr/iface/unused/unused.go b/vendor/github.com/uudashr/iface/unused/unused.go
deleted file mode 100644
index c2efbf52c..000000000
--- a/vendor/github.com/uudashr/iface/unused/unused.go
+++ /dev/null
@@ -1,138 +0,0 @@
-package unused
-
-import (
- "fmt"
- "go/ast"
- "go/token"
- "reflect"
- "slices"
- "strings"
-
- "github.com/uudashr/iface/internal/directive"
- "golang.org/x/tools/go/analysis"
- "golang.org/x/tools/go/analysis/passes/inspect"
- "golang.org/x/tools/go/ast/inspector"
-)
-
-// Analyzer is the unused interface analyzer.
-var Analyzer = newAnalyzer()
-
-func newAnalyzer() *analysis.Analyzer {
- r := runner{}
-
- analyzer := &analysis.Analyzer{
- Name: "unused",
- Doc: "Identifies interfaces that are not used anywhere in the same package where the interface is defined",
- URL: "https://pkg.go.dev/github.com/uudashr/iface/unused",
- Requires: []*analysis.Analyzer{inspect.Analyzer},
- Run: r.run,
- }
-
- analyzer.Flags.BoolVar(&r.debug, "debug", false, "enable debug mode")
- analyzer.Flags.StringVar(&r.exclude, "exclude", "", "comma-separated list of packages to exclude from the check")
-
- return analyzer
-}
-
-type runner struct {
- debug bool
- exclude string
-}
-
-func (r *runner) run(pass *analysis.Pass) (interface{}, error) {
- excludes := strings.Split(r.exclude, ",")
- if slices.Contains(excludes, pass.Pkg.Path()) {
- return nil, nil
- }
-
- inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
-
- // Collect all interface type declarations
- ifaceDecls := make(map[string]token.Pos)
-
- nodeFilter := []ast.Node{
- (*ast.GenDecl)(nil),
- }
-
- inspect.Preorder(nodeFilter, func(n ast.Node) {
- decl, ok := n.(*ast.GenDecl)
- if !ok {
- return
- }
-
- if r.debug {
- fmt.Printf("GenDecl: %v specs=%d\n", decl.Tok, len(decl.Specs))
- }
-
- if decl.Tok != token.TYPE {
- return
- }
-
- for i, spec := range decl.Specs {
- if r.debug {
- fmt.Printf(" spec[%d]: %v %v\n", i, spec, reflect.TypeOf(spec))
- }
-
- ts, ok := spec.(*ast.TypeSpec)
- if !ok {
- continue
- }
-
- _, ok = ts.Type.(*ast.InterfaceType)
- if !ok {
- return
- }
-
- if r.debug {
- fmt.Println(" Interface type declaration:", ts.Name.Name, ts.Pos())
- }
-
- dir := directive.ParseIgnore(decl.Doc)
- if dir != nil && dir.ShouldIgnore(pass.Analyzer.Name) {
- // skip due to ignore directive
- continue
- }
-
- ifaceDecls[ts.Name.Name] = ts.Pos()
- }
- })
-
- if r.debug {
- var ifaceNames []string
- for name := range ifaceDecls {
- ifaceNames = append(ifaceNames, name)
- }
-
- fmt.Println("Declared interfaces:", ifaceNames)
- }
-
- // Inspect whether the interface is used within the package
- nodeFilter = []ast.Node{
- (*ast.Ident)(nil),
- }
-
- inspect.Preorder(nodeFilter, func(n ast.Node) {
- ident, ok := n.(*ast.Ident)
- if !ok {
- return
- }
-
- pos := ifaceDecls[ident.Name]
- if pos == ident.Pos() {
- // The identifier is the interface type declaration
- return
- }
-
- delete(ifaceDecls, ident.Name)
- })
-
- if r.debug {
- fmt.Printf("Package %s %s\n", pass.Pkg.Path(), pass.Pkg.Name())
- }
-
- for name, pos := range ifaceDecls {
- pass.Reportf(pos, "interface %s is declared but not used within the package", name)
- }
-
- return nil, nil
-}