aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/gostaticanalysis
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/gostaticanalysis
parent475a4c203afb8b7d3af51c4fd32bb170ff32a45e (diff)
vendor: delete
Diffstat (limited to 'vendor/github.com/gostaticanalysis')
-rw-r--r--vendor/github.com/gostaticanalysis/analysisutil/LICENSE21
-rw-r--r--vendor/github.com/gostaticanalysis/analysisutil/README.md5
-rw-r--r--vendor/github.com/gostaticanalysis/analysisutil/call.go405
-rw-r--r--vendor/github.com/gostaticanalysis/analysisutil/diagnostic.go45
-rw-r--r--vendor/github.com/gostaticanalysis/analysisutil/file.go30
-rw-r--r--vendor/github.com/gostaticanalysis/analysisutil/pkg.go49
-rw-r--r--vendor/github.com/gostaticanalysis/analysisutil/ssa.go152
-rw-r--r--vendor/github.com/gostaticanalysis/analysisutil/ssainspect.go47
-rw-r--r--vendor/github.com/gostaticanalysis/analysisutil/types.go228
-rw-r--r--vendor/github.com/gostaticanalysis/comment/LICENSE21
-rw-r--r--vendor/github.com/gostaticanalysis/comment/README.md10
-rw-r--r--vendor/github.com/gostaticanalysis/comment/comment.go152
-rw-r--r--vendor/github.com/gostaticanalysis/comment/passes/commentmap/commentmap.go21
-rw-r--r--vendor/github.com/gostaticanalysis/forcetypeassert/.reviewdog.yml8
-rw-r--r--vendor/github.com/gostaticanalysis/forcetypeassert/LICENSE21
-rw-r--r--vendor/github.com/gostaticanalysis/forcetypeassert/README.md28
-rw-r--r--vendor/github.com/gostaticanalysis/forcetypeassert/forcetypeassert.go143
-rw-r--r--vendor/github.com/gostaticanalysis/nilerr/LICENSE21
-rw-r--r--vendor/github.com/gostaticanalysis/nilerr/README.md41
-rw-r--r--vendor/github.com/gostaticanalysis/nilerr/nilerr.go291
20 files changed, 0 insertions, 1739 deletions
diff --git a/vendor/github.com/gostaticanalysis/analysisutil/LICENSE b/vendor/github.com/gostaticanalysis/analysisutil/LICENSE
deleted file mode 100644
index bf7e33db8..000000000
--- a/vendor/github.com/gostaticanalysis/analysisutil/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2019 GoStaticAnalysis
-
-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/gostaticanalysis/analysisutil/README.md b/vendor/github.com/gostaticanalysis/analysisutil/README.md
deleted file mode 100644
index d8fd3d2a4..000000000
--- a/vendor/github.com/gostaticanalysis/analysisutil/README.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# analysisutil
-
-[![PkgGoDev](https://pkg.go.dev/badge/github.com/gostaticanalysis/analysisutil)](https://pkg.go.dev/github.com/gostaticanalysis/analysisutil)
-
-Utilities for x/tools/go/analysis package.
diff --git a/vendor/github.com/gostaticanalysis/analysisutil/call.go b/vendor/github.com/gostaticanalysis/analysisutil/call.go
deleted file mode 100644
index e3d98d1dc..000000000
--- a/vendor/github.com/gostaticanalysis/analysisutil/call.go
+++ /dev/null
@@ -1,405 +0,0 @@
-package analysisutil
-
-import (
- "go/types"
-
- "golang.org/x/tools/go/ssa"
-)
-
-// CalledChecker checks a function is called.
-// See From and Func.
-type CalledChecker struct {
- Ignore func(instr ssa.Instruction) bool
-}
-
-// NotIn checks whether receiver's method is called in a function.
-// If there is no methods calling at a path from an instruction
-// which type is receiver to all return instruction, NotIn returns these instructions.
-func (c *CalledChecker) NotIn(f *ssa.Function, receiver types.Type, methods ...*types.Func) []ssa.Instruction {
- done := map[ssa.Value]bool{}
- var instrs []ssa.Instruction
- for _, b := range f.Blocks {
- for i, instr := range b.Instrs {
- v, _ := instr.(ssa.Value)
- if v == nil || done[v] {
- continue
- }
-
- if v, _ := v.(*ssa.UnOp); v != nil && done[v.X] {
- continue
- }
-
- called, ok := c.From(b, i, receiver, methods...)
- if ok && !called {
- instrs = append(instrs, instr)
- done[v] = true
- if v, _ := v.(*ssa.UnOp); v != nil {
- done[v.X] = true
- }
- }
- }
- }
- return instrs
-}
-
-// Func returns true when f is called in the instr.
-// If recv is not nil, Func also checks the receiver.
-func (c *CalledChecker) Func(instr ssa.Instruction, recv ssa.Value, f *types.Func) bool {
-
- if c.Ignore != nil && c.Ignore(instr) {
- return false
- }
-
- call, ok := instr.(ssa.CallInstruction)
- if !ok {
- return false
- }
-
- common := call.Common()
- if common == nil {
- return false
- }
-
- callee := common.StaticCallee()
- if callee == nil {
- return false
- }
-
- fn, ok := callee.Object().(*types.Func)
- if !ok {
- return false
- }
-
- if recv != nil &&
- common.Signature().Recv() != nil &&
- (len(common.Args) == 0 && recv != nil || common.Args[0] != recv &&
- !referrer(recv, common.Args[0])) {
- return false
- }
-
- return fn == f
-}
-
-func referrer(a, b ssa.Value) bool {
- return isReferrerOf(a, b) || isReferrerOf(b, a)
-}
-
-func isReferrerOf(a, b ssa.Value) bool {
- if a == nil || b == nil {
- return false
- }
- if b.Referrers() != nil {
- brs := *b.Referrers()
-
- for _, br := range brs {
- brv, ok := br.(ssa.Value)
- if !ok {
- continue
- }
- if brv == a {
- return true
- }
- }
- }
- return false
-}
-
-// From checks whether receiver's method is called in an instruction
-// which belogns to after i-th instructions, or in succsor blocks of b.
-// The first result is above value.
-// The second result is whether type of i-th instruction does not much receiver
-// or matches with ignore cases.
-func (c *CalledChecker) From(b *ssa.BasicBlock, i int, receiver types.Type, methods ...*types.Func) (called, ok bool) {
- if b == nil || i < 0 || i >= len(b.Instrs) ||
- receiver == nil || len(methods) == 0 {
- return false, false
- }
-
- v, ok := b.Instrs[i].(ssa.Value)
- if !ok {
- return false, false
- }
-
- from := &calledFrom{recv: v, fs: methods, ignore: c.Ignore}
-
- if !from.isRecv(receiver, v.Type()) {
- return false, false
- }
-
- if from.ignored() {
- return false, false
- }
-
- if from.instrs(b.Instrs[i+1:]) ||
- from.succs(b) {
- return true, true
- }
-
- from.done = nil
- if from.storedInInstrs(b.Instrs[i+1:]) ||
- from.storedInSuccs(b) {
- return false, false
- }
-
- return false, true
-}
-
-type calledFrom struct {
- recv ssa.Value
- fs []*types.Func
- done map[*ssa.BasicBlock]bool
- ignore func(ssa.Instruction) bool
-}
-
-func (c *calledFrom) ignored() bool {
-
- switch v := c.recv.(type) {
- case *ssa.UnOp:
- switch v.X.(type) {
- case *ssa.FreeVar, *ssa.Global:
- return true
- }
- }
-
- refs := c.recv.Referrers()
- if refs == nil {
- return false
- }
-
- for _, ref := range *refs {
- done := map[ssa.Instruction]bool{}
- if !c.isOwn(ref) &&
- ((c.ignore != nil && c.ignore(ref)) ||
- c.isRet(ref, done) || c.isArg(ref)) {
- return true
- }
- }
-
- return false
-}
-
-func (c *calledFrom) isOwn(instr ssa.Instruction) bool {
- v, ok := instr.(ssa.Value)
- if !ok {
- return false
- }
- return v == c.recv
-}
-
-func (c *calledFrom) isRet(instr ssa.Instruction, done map[ssa.Instruction]bool) bool {
- if done[instr] {
- return false
- }
- done[instr] = true
-
- switch instr := instr.(type) {
- case *ssa.Return:
- return true
- case *ssa.MapUpdate:
- return c.isRetInRefs(instr.Map, done)
- case *ssa.Store:
- if instr, _ := instr.Addr.(ssa.Instruction); instr != nil {
- return c.isRet(instr, done)
- }
- return c.isRetInRefs(instr.Addr, done)
- case *ssa.FieldAddr:
- return c.isRetInRefs(instr.X, done)
- case ssa.Value:
- return c.isRetInRefs(instr, done)
- default:
- return false
- }
-}
-
-func (c *calledFrom) isRetInRefs(v ssa.Value, done map[ssa.Instruction]bool) bool {
- refs := v.Referrers()
- if refs == nil {
- return false
- }
- for _, ref := range *refs {
- if c.isRet(ref, done) {
- return true
- }
- }
- return false
-}
-
-func (c *calledFrom) isArg(instr ssa.Instruction) bool {
-
- call, ok := instr.(ssa.CallInstruction)
- if !ok {
- return false
- }
-
- common := call.Common()
- if common == nil {
- return false
- }
-
- args := common.Args
- if common.Signature().Recv() != nil {
- args = args[1:]
- }
-
- for i := range args {
- if args[i] == c.recv {
- return true
- }
- }
-
- return false
-}
-
-func (c *calledFrom) instrs(instrs []ssa.Instruction) bool {
- for _, instr := range instrs {
- for _, f := range c.fs {
- if Called(instr, c.recv, f) {
- return true
- }
- }
- }
- return false
-}
-
-func (c *calledFrom) succs(b *ssa.BasicBlock) bool {
- if c.done == nil {
- c.done = map[*ssa.BasicBlock]bool{}
- }
-
- if c.done[b] {
- return true
- }
- c.done[b] = true
-
- if len(b.Succs) == 0 {
- return false
- }
-
- for _, s := range b.Succs {
- if !c.instrs(s.Instrs) && !c.succs(s) {
- return false
- }
- }
-
- return true
-}
-
-func (c *calledFrom) storedInInstrs(instrs []ssa.Instruction) bool {
- for _, instr := range instrs {
- switch instr := instr.(type) {
- case *ssa.Store:
- if instr.Val == c.recv {
- return true
- }
- }
- }
- return false
-}
-
-func (c *calledFrom) storedInSuccs(b *ssa.BasicBlock) bool {
- if c.done == nil {
- c.done = map[*ssa.BasicBlock]bool{}
- }
-
- if c.done[b] {
- return true
- }
- c.done[b] = true
-
- if len(b.Succs) == 0 {
- return false
- }
-
- for _, s := range b.Succs {
- if !c.storedInInstrs(s.Instrs) && !c.succs(s) {
- return false
- }
- }
-
- return true
-}
-
-func (c *calledFrom) isRecv(recv, typ types.Type) bool {
- return recv == typ || identical(recv, typ) ||
- c.isRecvInTuple(recv, typ) || c.isRecvInEmbedded(recv, typ)
-}
-
-func (c *calledFrom) isRecvInTuple(recv, typ types.Type) bool {
- tuple, _ := typ.(*types.Tuple)
- if tuple == nil {
- return false
- }
-
- for i := 0; i < tuple.Len(); i++ {
- if c.isRecv(recv, tuple.At(i).Type()) {
- return true
- }
- }
-
- return false
-}
-
-func (c *calledFrom) isRecvInEmbedded(recv, typ types.Type) bool {
-
- var st *types.Struct
- switch typ := typ.(type) {
- case *types.Struct:
- st = typ
- case *types.Pointer:
- return c.isRecvInEmbedded(recv, typ.Elem())
- case *types.Named:
- return c.isRecvInEmbedded(recv, typ.Underlying())
- default:
- return false
- }
-
- for i := 0; i < st.NumFields(); i++ {
- field := st.Field(i)
- if !field.Embedded() {
- continue
- }
-
- ft := field.Type()
- if c.isRecv(recv, ft) {
- return true
- }
-
- var ptrOrUnptr types.Type
- switch ft := ft.(type) {
- case *types.Pointer:
- // struct { *T } -> T
- ptrOrUnptr = ft.Elem()
- default:
- // struct { T } -> *T
- ptrOrUnptr = types.NewPointer(ft)
- }
-
- if c.isRecv(recv, ptrOrUnptr) {
- return true
- }
- }
-
- return false
-}
-
-// NotCalledIn checks whether receiver's method is called in a function.
-// If there is no methods calling at a path from an instruction
-// which type is receiver to all return instruction, NotCalledIn returns these instructions.
-func NotCalledIn(f *ssa.Function, receiver types.Type, methods ...*types.Func) []ssa.Instruction {
- return new(CalledChecker).NotIn(f, receiver, methods...)
-}
-
-// CalledFrom checks whether receiver's method is called in an instruction
-// which belogns to after i-th instructions, or in succsor blocks of b.
-// The first result is above value.
-// The second result is whether type of i-th instruction does not much receiver
-// or matches with ignore cases.
-func CalledFrom(b *ssa.BasicBlock, i int, receiver types.Type, methods ...*types.Func) (called, ok bool) {
- return new(CalledChecker).From(b, i, receiver, methods...)
-}
-
-// Called returns true when f is called in the instr.
-// If recv is not nil, Called also checks the receiver.
-func Called(instr ssa.Instruction, recv ssa.Value, f *types.Func) bool {
- return new(CalledChecker).Func(instr, recv, f)
-}
diff --git a/vendor/github.com/gostaticanalysis/analysisutil/diagnostic.go b/vendor/github.com/gostaticanalysis/analysisutil/diagnostic.go
deleted file mode 100644
index a911db6f1..000000000
--- a/vendor/github.com/gostaticanalysis/analysisutil/diagnostic.go
+++ /dev/null
@@ -1,45 +0,0 @@
-package analysisutil
-
-import (
- "go/token"
-
- "github.com/gostaticanalysis/comment"
- "github.com/gostaticanalysis/comment/passes/commentmap"
- "golang.org/x/tools/go/analysis"
-)
-
-// ReportWithoutIgnore returns a report function which can set to (analysis.Pass).Report.
-// The report function ignores a diagnostic which annotated by ignore comment as the below.
-// //lint:ignore Check1[,Check2,...,CheckN] reason
-// names is a list of checker names.
-// If names was omitted, the report function ignores by pass.Analyzer.Name.
-func ReportWithoutIgnore(pass *analysis.Pass, names ...string) func(analysis.Diagnostic) {
- cmaps, _ := pass.ResultOf[commentmap.Analyzer].(comment.Maps)
- if cmaps == nil {
- cmaps = comment.New(pass.Fset, pass.Files)
- }
-
- if len(names) == 0 {
- names = []string{pass.Analyzer.Name}
- }
-
- report := pass.Report // original report func
-
- return func(d analysis.Diagnostic) {
- start := pass.Fset.File(d.Pos).Line(d.Pos)
- end := start
- if d.End != token.NoPos {
- end = pass.Fset.File(d.End).Line(d.End)
- }
-
- for l := start; l <= end; l++ {
- for _, n := range names {
- if cmaps.IgnoreLine(pass.Fset, l, n) {
- return
- }
- }
- }
-
- report(d)
- }
-}
diff --git a/vendor/github.com/gostaticanalysis/analysisutil/file.go b/vendor/github.com/gostaticanalysis/analysisutil/file.go
deleted file mode 100644
index b9b295530..000000000
--- a/vendor/github.com/gostaticanalysis/analysisutil/file.go
+++ /dev/null
@@ -1,30 +0,0 @@
-package analysisutil
-
-import (
- "go/ast"
- "go/token"
- "regexp"
-
- "golang.org/x/tools/go/analysis"
-)
-
-// File finds *ast.File in pass.Files by pos.
-func File(pass *analysis.Pass, pos token.Pos) *ast.File {
- for _, f := range pass.Files {
- if f.Pos() <= pos && pos <= f.End() {
- return f
- }
- }
- return nil
-}
-
-var genCommentRegexp = regexp.MustCompile(`^// Code generated .* DO NOT EDIT\.$`)
-
-// IsGeneratedFile reports whether the file has been generated automatically.
-// If file is nil, IsGeneratedFile will return false.
-func IsGeneratedFile(file *ast.File) bool {
- if file == nil || len(file.Comments) == 0 {
- return false
- }
- return genCommentRegexp.MatchString(file.Comments[0].List[0].Text)
-}
diff --git a/vendor/github.com/gostaticanalysis/analysisutil/pkg.go b/vendor/github.com/gostaticanalysis/analysisutil/pkg.go
deleted file mode 100644
index b64150d81..000000000
--- a/vendor/github.com/gostaticanalysis/analysisutil/pkg.go
+++ /dev/null
@@ -1,49 +0,0 @@
-package analysisutil
-
-import (
- "go/types"
- "strconv"
- "strings"
-
- "golang.org/x/tools/go/analysis"
-)
-
-// RemoVendor removes vendoring information from import path.
-func RemoveVendor(path string) string {
- i := strings.Index(path, "vendor/")
- if i >= 0 {
- return path[i+len("vendor/"):]
- }
- return path
-}
-
-// LookupFromImports finds an object from import paths.
-func LookupFromImports(imports []*types.Package, path, name string) types.Object {
- path = RemoveVendor(path)
- for i := range imports {
- if path == RemoveVendor(imports[i].Path()) {
- return imports[i].Scope().Lookup(name)
- }
- }
- return nil
-}
-
-// Imported returns true when the given pass imports the pkg.
-func Imported(pkgPath string, pass *analysis.Pass) bool {
- fs := pass.Files
- if len(fs) == 0 {
- return false
- }
- for _, f := range fs {
- for _, i := range f.Imports {
- path, err := strconv.Unquote(i.Path.Value)
- if err != nil {
- continue
- }
- if RemoveVendor(path) == pkgPath {
- return true
- }
- }
- }
- return false
-}
diff --git a/vendor/github.com/gostaticanalysis/analysisutil/ssa.go b/vendor/github.com/gostaticanalysis/analysisutil/ssa.go
deleted file mode 100644
index 2e22bbe79..000000000
--- a/vendor/github.com/gostaticanalysis/analysisutil/ssa.go
+++ /dev/null
@@ -1,152 +0,0 @@
-package analysisutil
-
-import (
- "golang.org/x/tools/go/ssa"
-)
-
-// IfInstr returns *ssa.If which is contained in the block b.
-// If the block b has not any if instruction, IfInstr returns nil.
-func IfInstr(b *ssa.BasicBlock) *ssa.If {
- if len(b.Instrs) == 0 {
- return nil
- }
-
- ifinstr, ok := b.Instrs[len(b.Instrs)-1].(*ssa.If)
- if !ok {
- return nil
- }
-
- return ifinstr
-}
-
-// Phi returns phi values which are contained in the block b.
-func Phi(b *ssa.BasicBlock) []*ssa.Phi {
- var phis []*ssa.Phi
- for _, instr := range b.Instrs {
- if phi, ok := instr.(*ssa.Phi); ok {
- phis = append(phis, phi)
- } else {
- // no more phi
- break
- }
- }
- return phis
-}
-
-// Returns returns a slice of *ssa.Return in the function.
-func Returns(v ssa.Value) []*ssa.Return {
- var fn *ssa.Function
- switch v := v.(type) {
- case *ssa.Function:
- fn = v
- case *ssa.MakeClosure:
- return Returns(v.Fn)
- default:
- return nil
- }
-
- var rets []*ssa.Return
- done := map[*ssa.BasicBlock]bool{}
- for _, b := range fn.Blocks {
- rets = append(rets, returnsInBlock(b, done)...)
- }
- return rets
-}
-
-func returnsInBlock(b *ssa.BasicBlock, done map[*ssa.BasicBlock]bool) (rets []*ssa.Return) {
- if done[b] {
- return nil
- }
- done[b] = true
-
- if b.Index != 0 && len(b.Preds) == 0 {
- return nil
- }
-
- if len(b.Instrs) != 0 {
- switch instr := b.Instrs[len(b.Instrs)-1].(type) {
- case *ssa.Return:
- rets = append(rets, instr)
- }
- }
-
- for _, s := range b.Succs {
- rets = append(rets, returnsInBlock(s, done)...)
- }
-
- return rets
-}
-
-// BinOp returns binary operator values which are contained in the block b.
-func BinOp(b *ssa.BasicBlock) []*ssa.BinOp {
- var binops []*ssa.BinOp
- for _, instr := range b.Instrs {
- if binop, ok := instr.(*ssa.BinOp); ok {
- binops = append(binops, binop)
- }
- }
- return binops
-}
-
-// Used returns an instruction which uses the value in the instructions.
-func Used(v ssa.Value, instrs []ssa.Instruction) ssa.Instruction {
- if len(instrs) == 0 || v.Referrers() == nil {
- return nil
- }
-
- for _, instr := range instrs {
- if used := usedInInstr(v, instr); used != nil {
- return used
- }
- }
-
- return nil
-}
-
-func usedInInstr(v ssa.Value, instr ssa.Instruction) ssa.Instruction {
- switch instr := instr.(type) {
- case *ssa.MakeClosure:
- return usedInClosure(v, instr)
- default:
- operands := instr.Operands(nil)
- for _, x := range operands {
- if x != nil && *x == v {
- return instr
- }
- }
- }
-
- switch v := v.(type) {
- case *ssa.UnOp:
- return usedInInstr(v.X, instr)
- }
-
- return nil
-}
-
-func usedInClosure(v ssa.Value, instr *ssa.MakeClosure) ssa.Instruction {
- fn, _ := instr.Fn.(*ssa.Function)
- if fn == nil {
- return nil
- }
-
- var fv *ssa.FreeVar
- for i := range instr.Bindings {
- if instr.Bindings[i] == v {
- fv = fn.FreeVars[i]
- break
- }
- }
-
- if fv == nil {
- return nil
- }
-
- for _, b := range fn.Blocks {
- if used := Used(fv, b.Instrs); used != nil {
- return used
- }
- }
-
- return nil
-}
diff --git a/vendor/github.com/gostaticanalysis/analysisutil/ssainspect.go b/vendor/github.com/gostaticanalysis/analysisutil/ssainspect.go
deleted file mode 100644
index b2ae75f24..000000000
--- a/vendor/github.com/gostaticanalysis/analysisutil/ssainspect.go
+++ /dev/null
@@ -1,47 +0,0 @@
-package analysisutil
-
-import "golang.org/x/tools/go/ssa"
-
-// InspectFuncs inspects functions.
-func InspectFuncs(funcs []*ssa.Function, f func(i int, instr ssa.Instruction) bool) {
- for _, fun := range funcs {
- if len(fun.Blocks) == 0 {
- continue
- }
- new(instrInspector).block(fun.Blocks[0], 0, f)
- }
-}
-
-// InspectInstr inspects from i-th instruction of start block to succsessor blocks.
-func InspectInstr(start *ssa.BasicBlock, i int, f func(i int, instr ssa.Instruction) bool) {
- new(instrInspector).block(start, i, f)
-}
-
-type instrInspector struct {
- done map[*ssa.BasicBlock]bool
-}
-
-func (ins *instrInspector) block(b *ssa.BasicBlock, i int, f func(i int, instr ssa.Instruction) bool) {
- if ins.done == nil {
- ins.done = map[*ssa.BasicBlock]bool{}
- }
-
- if b == nil || ins.done[b] || len(b.Instrs) <= i {
- return
- }
-
- ins.done[b] = true
- ins.instrs(i, b.Instrs[i:], f)
- for _, s := range b.Succs {
- ins.block(s, 0, f)
- }
-
-}
-
-func (ins *instrInspector) instrs(offset int, instrs []ssa.Instruction, f func(i int, instr ssa.Instruction) bool) {
- for i, instr := range instrs {
- if !f(offset+i, instr) {
- break
- }
- }
-}
diff --git a/vendor/github.com/gostaticanalysis/analysisutil/types.go b/vendor/github.com/gostaticanalysis/analysisutil/types.go
deleted file mode 100644
index 8265efc8e..000000000
--- a/vendor/github.com/gostaticanalysis/analysisutil/types.go
+++ /dev/null
@@ -1,228 +0,0 @@
-package analysisutil
-
-import (
- "go/ast"
- "go/types"
-
- "golang.org/x/tools/go/analysis"
-)
-
-var errType = types.Universe.Lookup("error").Type().Underlying().(*types.Interface)
-
-// ImplementsError return whether t implements error interface.
-func ImplementsError(t types.Type) bool {
- return types.Implements(t, errType)
-}
-
-// ObjectOf returns types.Object by given name in the package.
-func ObjectOf(pass *analysis.Pass, pkg, name string) types.Object {
- obj := LookupFromImports(pass.Pkg.Imports(), pkg, name)
- if obj != nil {
- return obj
- }
- if RemoveVendor(pass.Pkg.Name()) != RemoveVendor(pkg) {
- return nil
- }
- return pass.Pkg.Scope().Lookup(name)
-}
-
-// TypeOf returns types.Type by given name in the package.
-// TypeOf accepts pointer types such as *T.
-func TypeOf(pass *analysis.Pass, pkg, name string) types.Type {
- if name == "" {
- return nil
- }
-
- if name[0] == '*' {
- obj := TypeOf(pass, pkg, name[1:])
- if obj == nil {
- return nil
- }
- return types.NewPointer(obj)
- }
-
- obj := ObjectOf(pass, pkg, name)
- if obj == nil {
- return nil
- }
-
- return obj.Type()
-}
-
-// MethodOf returns a method which has given name in the type.
-func MethodOf(typ types.Type, name string) *types.Func {
- switch typ := typ.(type) {
- case *types.Named:
- for i := 0; i < typ.NumMethods(); i++ {
- if f := typ.Method(i); f.Name() == name {
- return f
- }
- }
- case *types.Pointer:
- return MethodOf(typ.Elem(), name)
- }
- return nil
-}
-
-// see: https://github.com/golang/go/issues/19670
-func identical(x, y types.Type) (ret bool) {
- defer func() {
- r := recover()
- switch r := r.(type) {
- case string:
- if r == "unreachable" {
- ret = false
- return
- }
- case nil:
- return
- }
- panic(r)
- }()
- return types.Identical(x, y)
-}
-
-// Interfaces returns a map of interfaces which are declared in the package.
-func Interfaces(pkg *types.Package) map[string]*types.Interface {
- ifs := map[string]*types.Interface{}
-
- for _, n := range pkg.Scope().Names() {
- o := pkg.Scope().Lookup(n)
- if o != nil {
- i, ok := o.Type().Underlying().(*types.Interface)
- if ok {
- ifs[n] = i
- }
- }
- }
-
- return ifs
-}
-
-// Structs returns a map of structs which are declared in the package.
-func Structs(pkg *types.Package) map[string]*types.Struct {
- structs := map[string]*types.Struct{}
-
- for _, n := range pkg.Scope().Names() {
- o := pkg.Scope().Lookup(n)
- if o != nil {
- s, ok := o.Type().Underlying().(*types.Struct)
- if ok {
- structs[n] = s
- }
- }
- }
-
- return structs
-}
-
-// HasField returns whether the struct has the field.
-func HasField(s *types.Struct, f *types.Var) bool {
- if s == nil || f == nil {
- return false
- }
-
- for i := 0; i < s.NumFields(); i++ {
- if s.Field(i) == f {
- return true
- }
- }
-
- return false
-}
-
-// Field returns field of the struct type.
-// If the type is not struct or has not the field,
-// Field returns -1, nil.
-// If the type is a named type or a pointer type,
-// Field calls itself recursively with
-// an underlying type or an element type of pointer.
-func Field(t types.Type, name string) (int, *types.Var) {
- switch t := t.(type) {
- case *types.Pointer:
- return Field(t.Elem(), name)
- case *types.Named:
- return Field(t.Underlying(), name)
- case *types.Struct:
- for i := 0; i < t.NumFields(); i++ {
- f := t.Field(i)
- if f.Name() == name {
- return i, f
- }
- }
- }
-
- return -1, nil
-}
-
-func TypesInfo(info ...*types.Info) *types.Info {
- if len(info) == 0 {
- return nil
- }
-
- var merged types.Info
- for i := range info {
- mergeTypesInfo(&merged, info[i])
- }
-
- return &merged
-}
-
-func mergeTypesInfo(i1, i2 *types.Info) {
- // Types
- if i1.Types == nil && i2.Types != nil {
- i1.Types = map[ast.Expr]types.TypeAndValue{}
- }
- for expr, tv := range i2.Types {
- i1.Types[expr] = tv
- }
-
- // Defs
- if i1.Defs == nil && i2.Defs != nil {
- i1.Defs = map[*ast.Ident]types.Object{}
- }
- for ident, obj := range i2.Defs {
- i1.Defs[ident] = obj
- }
-
- // Uses
- if i1.Uses == nil && i2.Uses != nil {
- i1.Uses = map[*ast.Ident]types.Object{}
- }
- for ident, obj := range i2.Uses {
- i1.Uses[ident] = obj
- }
-
- // Implicits
- if i1.Implicits == nil && i2.Implicits != nil {
- i1.Implicits = map[ast.Node]types.Object{}
- }
- for n, obj := range i2.Implicits {
- i1.Implicits[n] = obj
- }
-
- // Selections
- if i1.Selections == nil && i2.Selections != nil {
- i1.Selections = map[*ast.SelectorExpr]*types.Selection{}
- }
- for expr, sel := range i2.Selections {
- i1.Selections[expr] = sel
- }
-
- // Scopes
- if i1.Scopes == nil && i2.Scopes != nil {
- i1.Scopes = map[ast.Node]*types.Scope{}
- }
- for n, s := range i2.Scopes {
- i1.Scopes[n] = s
- }
-
- // InitOrder
- i1.InitOrder = append(i1.InitOrder, i2.InitOrder...)
-}
-
-// Under returns the most bottom underlying type.
-// Deprecated: (types.Type).Underlying returns same value of it.
-func Under(t types.Type) types.Type {
- return t.Underlying()
-}
diff --git a/vendor/github.com/gostaticanalysis/comment/LICENSE b/vendor/github.com/gostaticanalysis/comment/LICENSE
deleted file mode 100644
index 4f7eeff5b..000000000
--- a/vendor/github.com/gostaticanalysis/comment/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2018 Takuya Ueda
-
-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/gostaticanalysis/comment/README.md b/vendor/github.com/gostaticanalysis/comment/README.md
deleted file mode 100644
index 533555313..000000000
--- a/vendor/github.com/gostaticanalysis/comment/README.md
+++ /dev/null
@@ -1,10 +0,0 @@
-# gostaticanalysis/comment
-
-[![godoc.org][godoc-badge]][godoc]
-
-`comment` provides utilities for [ast.CommentMap](https://golang.org/pkg/go/ast/#CommentMap).
-
-<!-- links -->
-[godoc]: https://godoc.org/github.com/gostaticanalysis/comment
-[godoc-badge]: https://img.shields.io/badge/godoc-reference-4F73B3.svg?style=flat-square&label=%20godoc.org
-
diff --git a/vendor/github.com/gostaticanalysis/comment/comment.go b/vendor/github.com/gostaticanalysis/comment/comment.go
deleted file mode 100644
index 79cb09382..000000000
--- a/vendor/github.com/gostaticanalysis/comment/comment.go
+++ /dev/null
@@ -1,152 +0,0 @@
-package comment
-
-import (
- "go/ast"
- "go/token"
- "strings"
-)
-
-// Maps is slice of ast.CommentMap.
-type Maps []ast.CommentMap
-
-// New creates new a CommentMap slice from specified files.
-func New(fset *token.FileSet, files []*ast.File) Maps {
- maps := make(Maps, len(files))
- for i := range files {
- maps[i] = ast.NewCommentMap(fset, files[i], files[i].Comments)
- }
- return maps
-}
-
-// Comments returns correspond a CommentGroup slice to specified AST node.
-func (maps Maps) Comments(n ast.Node) []*ast.CommentGroup {
- for i := range maps {
- if maps[i][n] != nil {
- return maps[i][n]
- }
- }
- return nil
-}
-
-// CommentsByPos returns correspond a CommentGroup slice to specified pos.
-func (maps Maps) CommentsByPos(pos token.Pos) []*ast.CommentGroup {
- for i := range maps {
- for n, cgs := range maps[i] {
- if n.Pos() == pos {
- return cgs
- }
- }
- }
- return nil
-}
-
-// Annotated checks either specified AST node is annotated or not.
-func (maps Maps) Annotated(n ast.Node, annotation string) bool {
- for _, cg := range maps.Comments(n) {
- if strings.HasPrefix(strings.TrimSpace(cg.Text()), annotation) {
- return true
- }
- }
- return false
-}
-
-// Ignore checks either specified AST node is ignored by the check.
-// It follows staticcheck style as the below.
-// //lint:ignore Check1[,Check2,...,CheckN] reason
-func (maps Maps) Ignore(n ast.Node, check string) bool {
- for _, cg := range maps.Comments(n) {
- if hasIgnoreCheck(cg, check) {
- return true
- }
- }
- return false
-}
-
-// IgnorePos checks either specified postion of AST node is ignored by the check.
-// It follows staticcheck style as the below.
-// //lint:ignore Check1[,Check2,...,CheckN] reason
-func (maps Maps) IgnorePos(pos token.Pos, check string) bool {
- for _, cg := range maps.CommentsByPos(pos) {
- if hasIgnoreCheck(cg, check) {
- return true
- }
- }
- return false
-}
-
-// Deprecated: This function does not work with multiple files.
-// CommentsByPosLine can be used instead of CommentsByLine.
-//
-// CommentsByLine returns correspond a CommentGroup slice to specified line.
-func (maps Maps) CommentsByLine(fset *token.FileSet, line int) []*ast.CommentGroup {
- for i := range maps {
- for n, cgs := range maps[i] {
- l := fset.File(n.Pos()).Line(n.Pos())
- if l == line {
- return cgs
- }
- }
- }
- return nil
-}
-
-// CommentsByPosLine returns correspond a CommentGroup slice to specified line.
-func (maps Maps) CommentsByPosLine(fset *token.FileSet, pos token.Pos) []*ast.CommentGroup {
- f1 := fset.File(pos)
- for i := range maps {
- for n, cgs := range maps[i] {
- f2 := fset.File(n.Pos())
- if f1 != f2 {
- // different file
- continue
- }
-
- if f1.Line(pos) == f2.Line(n.Pos()) {
- return cgs
- }
- }
- }
- return nil
-}
-
-// IgnoreLine checks either specified lineof AST node is ignored by the check.
-// It follows staticcheck style as the below.
-// //lint:ignore Check1[,Check2,...,CheckN] reason
-func (maps Maps) IgnoreLine(fset *token.FileSet, line int, check string) bool {
- for _, cg := range maps.CommentsByLine(fset, line) {
- if hasIgnoreCheck(cg, check) {
- return true
- }
- }
- return false
-}
-
-// hasIgnoreCheck returns true if the provided CommentGroup starts with a comment
-// of the form "//lint:ignore Check1[,Check2,...,CheckN] reason" and one of the
-// checks matches the provided check.
-//
-// The *ast.CommentGroup is checked directly rather than using "cg.Text()" because,
-// starting in Go 1.15, the "cg.Text()" call no longer returns directive-style
-// comments (see https://github.com/golang/go/issues/37974).
-func hasIgnoreCheck(cg *ast.CommentGroup, check string) bool {
- for _, list := range cg.List {
- if !strings.HasPrefix(list.Text, "//") {
- continue
- }
-
- s := strings.TrimSpace(list.Text[2:]) // list.Text[2:]: trim "//"
- txt := strings.Split(s, " ")
- if len(txt) < 3 || txt[0] != "lint:ignore" {
- continue
- }
-
- checks := strings.Split(txt[1], ",") // txt[1]: trim "lint:ignore"
- for i := range checks {
- if check == checks[i] {
- return true
- }
- }
- }
-
- return false
-}
diff --git a/vendor/github.com/gostaticanalysis/comment/passes/commentmap/commentmap.go b/vendor/github.com/gostaticanalysis/comment/passes/commentmap/commentmap.go
deleted file mode 100644
index 1b60a160c..000000000
--- a/vendor/github.com/gostaticanalysis/comment/passes/commentmap/commentmap.go
+++ /dev/null
@@ -1,21 +0,0 @@
-package commentmap
-
-import (
- "reflect"
-
- "golang.org/x/tools/go/analysis"
-
- "github.com/gostaticanalysis/comment"
-)
-
-var Analyzer = &analysis.Analyzer{
- Name: "commentmap",
- Doc: "create comment map",
- Run: run,
- RunDespiteErrors: true,
- ResultType: reflect.TypeOf(comment.Maps{}),
-}
-
-func run(pass *analysis.Pass) (interface{}, error) {
- return comment.New(pass.Fset, pass.Files), nil
-}
diff --git a/vendor/github.com/gostaticanalysis/forcetypeassert/.reviewdog.yml b/vendor/github.com/gostaticanalysis/forcetypeassert/.reviewdog.yml
deleted file mode 100644
index 2e243ff73..000000000
--- a/vendor/github.com/gostaticanalysis/forcetypeassert/.reviewdog.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-runner:
- golint:
- cmd: golint ./...
- errorformat:
- - "%f:%l:%c: %m"
- level: warning
- govet:
- cmd: go vet -all .
diff --git a/vendor/github.com/gostaticanalysis/forcetypeassert/LICENSE b/vendor/github.com/gostaticanalysis/forcetypeassert/LICENSE
deleted file mode 100644
index bf7e33db8..000000000
--- a/vendor/github.com/gostaticanalysis/forcetypeassert/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2019 GoStaticAnalysis
-
-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/gostaticanalysis/forcetypeassert/README.md b/vendor/github.com/gostaticanalysis/forcetypeassert/README.md
deleted file mode 100644
index 36a47594e..000000000
--- a/vendor/github.com/gostaticanalysis/forcetypeassert/README.md
+++ /dev/null
@@ -1,28 +0,0 @@
-# forcetypeassert
-
-[![godoc.org][godoc-badge]][godoc]
-
-`forcetypeassert` finds type assertions which did forcely such as below.
-
-```go
-func f() {
- var a interface{}
- _ = a.(int) // type assertion must be checked
-}
-```
-
-You need to check if the assertion failed like so:
-```go
-func f() {
- var a interface{}
- _, ok := a.(int)
- if !ok { // type assertion failed
- // handle error
- }
-}
-```
-
-<!-- links -->
-[godoc]: https://godoc.org/github.com/gostaticanalysis/forcetypeassert
-[godoc-badge]: https://img.shields.io/badge/godoc-reference-4F73B3.svg?style=flat-square&label=%20godoc.org
-
diff --git a/vendor/github.com/gostaticanalysis/forcetypeassert/forcetypeassert.go b/vendor/github.com/gostaticanalysis/forcetypeassert/forcetypeassert.go
deleted file mode 100644
index bb48485d9..000000000
--- a/vendor/github.com/gostaticanalysis/forcetypeassert/forcetypeassert.go
+++ /dev/null
@@ -1,143 +0,0 @@
-package forcetypeassert
-
-import (
- "go/ast"
- "reflect"
-
- "golang.org/x/tools/go/analysis"
- "golang.org/x/tools/go/analysis/passes/inspect"
- "golang.org/x/tools/go/ast/inspector"
-)
-
-var Analyzer = &analysis.Analyzer{
- Name: "forcetypeassert",
- Doc: Doc,
- Run: run,
- Requires: []*analysis.Analyzer{
- inspect.Analyzer,
- },
- ResultType: reflect.TypeOf((*Panicable)(nil)),
-}
-
-// Panicable stores panicable type assertions.
-type Panicable struct {
- m map[ast.Node]bool
- nodes []ast.Node
-}
-
-// Check checks whether the node may occur panic or not.
-func (p *Panicable) Check(n ast.Node) bool {
- return p.m[n]
-}
-
-// Len is number of panicable nodes.
-func (p *Panicable) Len() int {
- return len(p.nodes)
-}
-
-// At returns the i-th panicable node.
-func (p *Panicable) At(i int) ast.Node {
- return p.nodes[i]
-}
-
-const Doc = "forcetypeassert is finds type assertions which did forcely"
-
-func run(pass *analysis.Pass) (interface{}, error) {
- inspect, _ := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
- result := &Panicable{m: make(map[ast.Node]bool)}
-
- nodeFilter := []ast.Node{
- (*ast.AssignStmt)(nil),
- (*ast.ValueSpec)(nil),
- (*ast.TypeAssertExpr)(nil),
- }
-
- inspect.Nodes(nodeFilter, func(n ast.Node, push bool) bool {
- if !push {
- return false
- }
- switch n := n.(type) {
- case *ast.AssignStmt:
- return checkAssignStmt(pass, result, n)
- case *ast.ValueSpec:
- return checkValueSpec(pass, result, n)
- case *ast.TypeAssertExpr:
- if n.Type != nil {
- result.m[n] = true
- result.nodes = append(result.nodes, n)
- pass.Reportf(n.Pos(), "type assertion must be checked")
- }
- return false
- }
-
- return true
- })
-
- return result, nil
-}
-
-func checkAssignStmt(pass *analysis.Pass, result *Panicable, n *ast.AssignStmt) bool {
- tae := findTypeAssertion(n.Rhs)
- if tae == nil {
- return true
- }
-
- switch {
- // if right hand has 2 or more values, assign statement can't assert boolean value which describes type assertion is succeeded
- case len(n.Rhs) > 1:
- pass.Reportf(n.Pos(), "right hand must be only type assertion")
- return false
- case len(n.Lhs) != 2 && tae.Type != nil:
- result.m[n] = true
- result.nodes = append(result.nodes, n)
- pass.Reportf(n.Pos(), "type assertion must be checked")
- return false
- case len(n.Lhs) == 2:
- return false
- }
-
- return true
-}
-
-func checkValueSpec(pass *analysis.Pass, result *Panicable, n *ast.ValueSpec) bool {
- tae := findTypeAssertion(n.Values)
- if tae == nil {
- return true
- }
-
- switch {
- // if right hand has 2 or more values, assign statement can't assert boolean value which describes type assertion is succeeded
- case len(n.Values) > 1:
- pass.Reportf(n.Pos(), "right hand must be only type assertion")
- return false
- case len(n.Names) != 2 && tae.Type != nil:
- result.m[n] = true
- result.nodes = append(result.nodes, n)
- pass.Reportf(n.Pos(), "type assertion must be checked")
- return false
- case len(n.Names) == 2:
- return false
- }
-
- return true
-}
-
-func findTypeAssertion(exprs []ast.Expr) *ast.TypeAssertExpr {
- for _, expr := range exprs {
- var typeAssertExpr *ast.TypeAssertExpr
- ast.Inspect(expr, func(n ast.Node) bool {
- switch n := n.(type) {
- case *ast.FuncLit:
- return false
- case *ast.TypeAssertExpr:
- typeAssertExpr = n
- return false
- }
- return true
- })
- if typeAssertExpr != nil {
- return typeAssertExpr
- }
- }
- return nil
-}
diff --git a/vendor/github.com/gostaticanalysis/nilerr/LICENSE b/vendor/github.com/gostaticanalysis/nilerr/LICENSE
deleted file mode 100644
index bf7e33db8..000000000
--- a/vendor/github.com/gostaticanalysis/nilerr/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2019 GoStaticAnalysis
-
-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/gostaticanalysis/nilerr/README.md b/vendor/github.com/gostaticanalysis/nilerr/README.md
deleted file mode 100644
index d6b4acf8b..000000000
--- a/vendor/github.com/gostaticanalysis/nilerr/README.md
+++ /dev/null
@@ -1,41 +0,0 @@
-# nilerr
-
-[![pkg.go.dev][gopkg-badge]][gopkg]
-
-`nilerr` finds code which returns nil even though it checks that error is not nil.
-
-```go
-func f() error {
- err := do()
- if err != nil {
- return nil // miss
- }
-}
-```
-
-`nilerr` also finds code which returns error even though it checks that error is nil.
-
-```go
-func f() error {
- err := do()
- if err == nil {
- return err // miss
- }
-}
-```
-
-`nilerr` ignores code which has a miss with ignore comment.
-
-```go
-func f() error {
- err := do()
- if err != nil {
- //lint:ignore nilerr reason
- return nil // ignore
- }
-}
-```
-
-<!-- links -->
-[gopkg]: https://pkg.go.dev/github.com/gostaticanalysis/nilerr
-[gopkg-badge]: https://pkg.go.dev/badge/github.com/gostaticanalysis/nilerr?status.svg
diff --git a/vendor/github.com/gostaticanalysis/nilerr/nilerr.go b/vendor/github.com/gostaticanalysis/nilerr/nilerr.go
deleted file mode 100644
index 787a9e1e9..000000000
--- a/vendor/github.com/gostaticanalysis/nilerr/nilerr.go
+++ /dev/null
@@ -1,291 +0,0 @@
-package nilerr
-
-import (
- "fmt"
- "go/token"
- "go/types"
-
- "github.com/gostaticanalysis/comment"
- "github.com/gostaticanalysis/comment/passes/commentmap"
- "golang.org/x/tools/go/analysis"
- "golang.org/x/tools/go/analysis/passes/buildssa"
- "golang.org/x/tools/go/ssa"
-)
-
-var Analyzer = &analysis.Analyzer{
- Name: "nilerr",
- Doc: Doc,
- Run: run,
- Requires: []*analysis.Analyzer{
- buildssa.Analyzer,
- commentmap.Analyzer,
- },
-}
-
-const Doc = "nilerr checks returning nil when err is not nil"
-
-func run(pass *analysis.Pass) (interface{}, error) {
- funcs := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA).SrcFuncs
- cmaps := pass.ResultOf[commentmap.Analyzer].(comment.Maps)
-
- reportFail := func(v ssa.Value, ret *ssa.Return, format string) {
- pos := ret.Pos()
- line := getNodeLineNumber(pass, ret)
- errLines := getValueLineNumbers(pass, v)
- if !cmaps.IgnoreLine(pass.Fset, line, "nilerr") {
- var errLineText string
- if len(errLines) == 1 {
- errLineText = fmt.Sprintf("line %d", errLines[0])
- } else {
- errLineText = fmt.Sprintf("lines %v", errLines)
- }
- pass.Reportf(pos, format, errLineText)
- }
- }
-
- for i := range funcs {
- for _, b := range funcs[i].Blocks {
- if v := binOpErrNil(b, token.NEQ); v != nil {
- if ret := isReturnNil(b.Succs[0]); ret != nil {
- if !usesErrorValue(b.Succs[0], v) {
- reportFail(v, ret, "error is not nil (%s) but it returns nil")
- }
- }
- } else if v := binOpErrNil(b, token.EQL); v != nil {
- if len(b.Succs[0].Preds) == 1 { // if there are multiple conditions, this may be false positive
- if ret := isReturnError(b.Succs[0], v); ret != nil {
- reportFail(v, ret, "error is nil (%s) but it returns error")
- }
- }
- }
-
- }
- }
-
- return nil, nil
-}
-
-func getValueLineNumbers(pass *analysis.Pass, v ssa.Value) []int {
- if phi, ok := v.(*ssa.Phi); ok {
- result := make([]int, 0, len(phi.Edges))
- for _, edge := range phi.Edges {
- result = append(result, getValueLineNumbers(pass, edge)...)
- }
- return result
- }
-
- value := v
- if extract, ok := value.(*ssa.Extract); ok {
- value = extract.Tuple
- }
-
- pos := value.Pos()
- return []int{pass.Fset.File(pos).Line(pos)}
-}
-
-func getNodeLineNumber(pass *analysis.Pass, node ssa.Node) int {
- pos := node.Pos()
- return pass.Fset.File(pos).Line(pos)
-}
-
-var errType = types.Universe.Lookup("error").Type().Underlying().(*types.Interface)
-
-func binOpErrNil(b *ssa.BasicBlock, op token.Token) ssa.Value {
- if len(b.Instrs) == 0 {
- return nil
- }
-
- ifinst, ok := b.Instrs[len(b.Instrs)-1].(*ssa.If)
- if !ok {
- return nil
- }
-
- binop, ok := ifinst.Cond.(*ssa.BinOp)
- if !ok {
- return nil
- }
-
- if binop.Op != op {
- return nil
- }
-
- if !types.Implements(binop.X.Type(), errType) {
- return nil
- }
-
- if !types.Implements(binop.Y.Type(), errType) {
- return nil
- }
-
- xIsConst, yIsConst := isConst(binop.X), isConst(binop.Y)
- switch {
- case !xIsConst && yIsConst: // err != nil or err == nil
- return binop.X
- case xIsConst && !yIsConst: // nil != err or nil == err
- return binop.Y
- }
-
- return nil
-}
-
-func isConst(v ssa.Value) bool {
- _, ok := v.(*ssa.Const)
- return ok
-}
-
-func isReturnNil(b *ssa.BasicBlock) *ssa.Return {
- if len(b.Instrs) == 0 {
- return nil
- }
-
- ret, ok := b.Instrs[len(b.Instrs)-1].(*ssa.Return)
- if !ok {
- return nil
- }
-
- errorReturnValues := 0
- for _, res := range ret.Results {
- if !types.Implements(res.Type(), errType) {
- continue
- }
-
- errorReturnValues++
- v, ok := res.(*ssa.Const)
- if !ok {
- return nil
- }
-
- if !v.IsNil() {
- return nil
- }
- }
-
- if errorReturnValues == 0 {
- return nil
- }
-
- return ret
-}
-
-func isReturnError(b *ssa.BasicBlock, errVal ssa.Value) *ssa.Return {
- if len(b.Instrs) == 0 {
- return nil
- }
-
- ret, ok := b.Instrs[len(b.Instrs)-1].(*ssa.Return)
- if !ok {
- return nil
- }
-
- for _, v := range ret.Results {
- if v == errVal {
- return ret
- }
- }
-
- return nil
-}
-
-func usesErrorValue(b *ssa.BasicBlock, errVal ssa.Value) bool {
- for _, instr := range b.Instrs {
- if callInstr, ok := instr.(*ssa.Call); ok {
- for _, arg := range callInstr.Call.Args {
- if isUsedInValue(arg, errVal) {
- return true
- }
-
- sliceArg, ok := arg.(*ssa.Slice)
- if ok {
- if isUsedInSlice(sliceArg, errVal) {
- return true
- }
- }
- }
- }
- }
- return false
-}
-
-type ReferrersHolder interface {
- Referrers() *[]ssa.Instruction
-}
-
-var _ ReferrersHolder = (ssa.Node)(nil)
-var _ ReferrersHolder = (ssa.Value)(nil)
-
-func isUsedInSlice(sliceArg *ssa.Slice, errVal ssa.Value) bool {
- var valueBuf [10]*ssa.Value
- operands := sliceArg.Operands(valueBuf[:0])
-
- var valuesToInspect []ssa.Value
- addValueForInspection := func(value ssa.Value) {
- if value != nil {
- valuesToInspect = append(valuesToInspect, value)
- }
- }
-
- var nodesToInspect []ssa.Node
- visitedNodes := map[ssa.Node]bool{}
- addNodeForInspection := func(node ssa.Node) {
- if !visitedNodes[node] {
- visitedNodes[node] = true
- nodesToInspect = append(nodesToInspect, node)
- }
- }
- addReferrersForInspection := func(h ReferrersHolder) {
- if h == nil {
- return
- }
-
- referrers := h.Referrers()
- if referrers == nil {
- return
- }
-
- for _, r := range *referrers {
- if node, ok := r.(ssa.Node); ok {
- addNodeForInspection(node)
- }
- }
- }
-
- for _, operand := range operands {
- addReferrersForInspection(*operand)
- addValueForInspection(*operand)
- }
-
- for i := 0; i < len(nodesToInspect); i++ {
- switch node := nodesToInspect[i].(type) {
- case *ssa.IndexAddr:
- addReferrersForInspection(node)
- case *ssa.Store:
- addValueForInspection(node.Val)
- }
- }
-
- for _, value := range valuesToInspect {
- if isUsedInValue(value, errVal) {
- return true
- }
- }
- return false
-}
-
-func isUsedInValue(value, lookedFor ssa.Value) bool {
- if value == lookedFor {
- return true
- }
-
- switch value := value.(type) {
- case *ssa.ChangeInterface:
- return isUsedInValue(value.X, lookedFor)
- case *ssa.MakeInterface:
- return isUsedInValue(value.X, lookedFor)
- case *ssa.Call:
- if value.Call.IsInvoke() {
- return isUsedInValue(value.Call.Value, lookedFor)
- }
- }
-
- return false
-}