parent
58845813da
commit
94eaa8f196
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
||||
github.com/OpenPeeDeeP/depguard v1.0.0
|
||||
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
|
||||
github.com/fatih/color v1.6.0
|
||||
github.com/go-critic/go-critic v0.3.5-0.20190526074819-1df300866540
|
||||
github.com/go-critic/go-critic v0.3.5-0.20190904082202-d79a9f0c64db
|
||||
github.com/go-lintpack/lintpack v0.5.2
|
||||
github.com/go-ole/go-ole v1.2.1 // indirect
|
||||
github.com/gobwas/glob v0.2.3 // indirect
|
||||
|
4
go.sum
4
go.sum
@ -10,8 +10,8 @@ github.com/fatih/color v1.6.0 h1:66qjqZk8kalYAvDRtM1AdAJQI0tj4Wrue3Eq3B3pmFU=
|
||||
github.com/fatih/color v1.6.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/go-critic/go-critic v0.3.5-0.20190526074819-1df300866540 h1:djv/qAomOVj8voCHt0M0OYwR/4vfDq1zNKSPKjJCexs=
|
||||
github.com/go-critic/go-critic v0.3.5-0.20190526074819-1df300866540/go.mod h1:+sE8vrLDS2M0pZkBk0wy6+nLdKexVDrl/jBqQOTDThA=
|
||||
github.com/go-critic/go-critic v0.3.5-0.20190904082202-d79a9f0c64db h1:GYXWx7Vr3+zv833u+8IoXbNnQY0AdXsxAgI0kX7xcwA=
|
||||
github.com/go-critic/go-critic v0.3.5-0.20190904082202-d79a9f0c64db/go.mod h1:+sE8vrLDS2M0pZkBk0wy6+nLdKexVDrl/jBqQOTDThA=
|
||||
github.com/go-lintpack/lintpack v0.5.2 h1:DI5mA3+eKdWeJ40nU4d6Wc26qmdG8RCi/btYq0TuRN0=
|
||||
github.com/go-lintpack/lintpack v0.5.2/go.mod h1:NwZuYi2nUHho8XEIZ6SIxihrnPoqBTDqfpXvXAN0sXM=
|
||||
github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E=
|
||||
|
3
vendor/github.com/go-critic/go-critic/checkers/dupArg_checker.go
generated
vendored
3
vendor/github.com/go-critic/go-critic/checkers/dupArg_checker.go
generated
vendored
@ -24,6 +24,9 @@ func init() {
|
||||
// args[xIndex] and args[yIndex] are equal.
|
||||
newMatcherFunc := func(xIndex, yIndex int) func(*ast.CallExpr) bool {
|
||||
return func(call *ast.CallExpr) bool {
|
||||
if len(call.Args) <= xIndex || len(call.Args) <= yIndex {
|
||||
return false
|
||||
}
|
||||
x := call.Args[xIndex]
|
||||
y := call.Args[yIndex]
|
||||
return astequal.Expr(x, y)
|
||||
|
68
vendor/github.com/go-critic/go-critic/checkers/regexpPattern_checker.go
generated
vendored
Normal file
68
vendor/github.com/go-critic/go-critic/checkers/regexpPattern_checker.go
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
package checkers
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/constant"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/go-lintpack/lintpack"
|
||||
"github.com/go-lintpack/lintpack/astwalk"
|
||||
)
|
||||
|
||||
func init() {
|
||||
var info lintpack.CheckerInfo
|
||||
info.Name = "regexpPattern"
|
||||
info.Tags = []string{"diagnostic", "experimental"}
|
||||
info.Summary = "Detects suspicious regexp patterns"
|
||||
info.Before = "regexp.MustCompile(`google.com|yandex.ru`)"
|
||||
info.After = "regexp.MustCompile(`google\\.com|yandex\\.ru`)"
|
||||
|
||||
collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker {
|
||||
domains := []string{
|
||||
"com",
|
||||
"org",
|
||||
"info",
|
||||
"net",
|
||||
"ru",
|
||||
"de",
|
||||
}
|
||||
|
||||
allDomains := strings.Join(domains, "|")
|
||||
domainRE := regexp.MustCompile(`[^\\]\.(` + allDomains + `)\b`)
|
||||
return astwalk.WalkerForExpr(®expPatternChecker{
|
||||
ctx: ctx,
|
||||
domainRE: domainRE,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
type regexpPatternChecker struct {
|
||||
astwalk.WalkHandler
|
||||
ctx *lintpack.CheckerContext
|
||||
|
||||
domainRE *regexp.Regexp
|
||||
}
|
||||
|
||||
func (c *regexpPatternChecker) VisitExpr(x ast.Expr) {
|
||||
call, ok := x.(*ast.CallExpr)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
switch qualifiedName(call.Fun) {
|
||||
case "regexp.Compile", "regexp.CompilePOSIX", "regexp.MustCompile", "regexp.MustCompilePosix":
|
||||
cv := c.ctx.TypesInfo.Types[call.Args[0]].Value
|
||||
if cv == nil || cv.Kind() != constant.String {
|
||||
return
|
||||
}
|
||||
s := constant.StringVal(cv)
|
||||
if m := c.domainRE.FindStringSubmatch(s); m != nil {
|
||||
c.warnDomain(call.Args[0], m[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *regexpPatternChecker) warnDomain(cause ast.Expr, domain string) {
|
||||
c.ctx.Warn(cause, "'.%s' should probably be '\\.%s'", domain, domain)
|
||||
}
|
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
@ -10,7 +10,7 @@ github.com/davecgh/go-spew/spew
|
||||
github.com/fatih/color
|
||||
# github.com/fsnotify/fsnotify v1.4.7
|
||||
github.com/fsnotify/fsnotify
|
||||
# github.com/go-critic/go-critic v0.3.5-0.20190526074819-1df300866540
|
||||
# github.com/go-critic/go-critic v0.3.5-0.20190904082202-d79a9f0c64db
|
||||
github.com/go-critic/go-critic/checkers
|
||||
github.com/go-critic/go-critic/checkers/internal/lintutil
|
||||
# github.com/go-lintpack/lintpack v0.5.2
|
||||
@ -187,6 +187,8 @@ github.com/stretchr/testify/require
|
||||
github.com/timakin/bodyclose/passes/bodyclose
|
||||
# github.com/ultraware/funlen v0.0.1 => github.com/golangci/funlen v0.0.0-20190909161642-5e59b9546114
|
||||
github.com/ultraware/funlen
|
||||
# github.com/ultraware/whitespace v0.0.2
|
||||
github.com/ultraware/whitespace
|
||||
# github.com/valyala/bytebufferpool v1.0.0
|
||||
github.com/valyala/bytebufferpool
|
||||
# github.com/valyala/quicktemplate v1.1.1
|
||||
|
Loading…
x
Reference in New Issue
Block a user