aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-critic
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2023-02-22 22:16:50 +0100
committerTaras Madan <tarasmadan@google.com>2023-02-24 12:47:23 +0100
commit4165372ec8fd142475a4e35fd0cf4f8042132208 (patch)
tree21cd62211b4dd80bee469054c5b65db77342333c /vendor/github.com/go-critic
parent2b3ed821a493b8936c8bacfa6f8b4f1c90a00855 (diff)
dependencies: update
set go min requirements to 1.19 update dependencies update vendor
Diffstat (limited to 'vendor/github.com/go-critic')
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/badCond_checker.go27
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/badRegexp_checker.go2
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/dupBranchBody_checker.go2
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/embedded_rules.go6
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/hugeParam_checker.go4
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/ifElseChain_checker.go23
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/internal/astwalk/local_def_visitor.go6
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/internal/astwalk/type_expr_walker.go5
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/newDeref_checker.go5
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/rangeValCopy_checker.go7
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/ruleguard_checker.go8
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/rulesdata/rulesdata.go1198
-rw-r--r--vendor/github.com/go-critic/go-critic/framework/linter/linter.go28
13 files changed, 716 insertions, 605 deletions
diff --git a/vendor/github.com/go-critic/go-critic/checkers/badCond_checker.go b/vendor/github.com/go-critic/go-critic/checkers/badCond_checker.go
index 149f0ac88..d3d139a08 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/badCond_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/badCond_checker.go
@@ -114,30 +114,43 @@ func (c *badCondChecker) checkForStmt(stmt *ast.ForStmt) {
iter := astcast.ToIdent(init.Lhs[0])
cond := astcast.ToBinaryExpr(stmt.Cond)
- if cond.Op != token.GTR || !astequal.Expr(iter, cond.X) {
+
+ var i, n ast.Expr
+ var op token.Token
+ switch {
+ case cond.Op == token.GTR && astequal.Expr(iter, cond.X):
+ i = cond.X
+ n = cond.Y
+ op = token.LSS
+ case cond.Op == token.LSS && astequal.Expr(iter, cond.Y):
+ i = cond.Y
+ n = cond.X
+ op = token.GTR
+ default:
return
}
- if !typep.SideEffectFree(c.ctx.TypesInfo, cond.Y) {
+
+ if !typep.SideEffectFree(c.ctx.TypesInfo, n) {
return
}
post := astcast.ToIncDecStmt(stmt.Post)
- if post.Tok != token.INC || !astequal.Expr(iter, post.X) {
+ if post.Tok != token.INC || !astequal.Expr(iter, i) {
return
}
- mutated := lintutil.CouldBeMutated(c.ctx.TypesInfo, stmt.Body, cond.Y) ||
+ mutated := lintutil.CouldBeMutated(c.ctx.TypesInfo, stmt.Body, n) ||
lintutil.CouldBeMutated(c.ctx.TypesInfo, stmt.Body, iter)
if mutated {
return
}
- c.warnForStmt(stmt, cond)
+ c.warnForStmt(stmt, op, cond)
}
-func (c *badCondChecker) warnForStmt(cause ast.Node, cond *ast.BinaryExpr) {
+func (c *badCondChecker) warnForStmt(cause ast.Node, op token.Token, cond *ast.BinaryExpr) {
suggest := astcopy.BinaryExpr(cond)
- suggest.Op = token.LSS
+ suggest.Op = op
c.ctx.Warn(cause, "`%s` in loop; probably meant `%s`?",
cond, suggest)
}
diff --git a/vendor/github.com/go-critic/go-critic/checkers/badRegexp_checker.go b/vendor/github.com/go-critic/go-critic/checkers/badRegexp_checker.go
index e0d4b7487..8a359000a 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/badRegexp_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/badRegexp_checker.go
@@ -365,7 +365,7 @@ func (c *badRegexpChecker) checkCharClassDups(cc syntax.Expr) {
}
// 2. Sort ranges, O(nlogn).
- sort.Slice(ranges, func(i, j int) bool {
+ sort.SliceStable(ranges, func(i, j int) bool {
return ranges[i].low < ranges[j].low
})
diff --git a/vendor/github.com/go-critic/go-critic/checkers/dupBranchBody_checker.go b/vendor/github.com/go-critic/go-critic/checkers/dupBranchBody_checker.go
index 83de50528..ad16e3b3f 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/dupBranchBody_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/dupBranchBody_checker.go
@@ -54,5 +54,5 @@ func (c *dupBranchBodyChecker) checkIf(stmt *ast.IfStmt) {
}
func (c *dupBranchBodyChecker) warnIf(cause ast.Node) {
- c.ctx.Warn(cause, "both branches in if statement has same body")
+ c.ctx.Warn(cause, "both branches in if statement have same body")
}
diff --git a/vendor/github.com/go-critic/go-critic/checkers/embedded_rules.go b/vendor/github.com/go-critic/go-critic/checkers/embedded_rules.go
index 8a53ee5e5..b17178e09 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/embedded_rules.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/embedded_rules.go
@@ -15,7 +15,7 @@ import (
//go:generate go run ./rules/precompile.go -rules ./rules/rules.go -o ./rulesdata/rulesdata.go
-func InitEmbeddedRules() {
+func InitEmbeddedRules() error {
filename := "rules/rules.go"
fset := token.NewFileSet()
@@ -44,7 +44,7 @@ func InitEmbeddedRules() {
},
}
if err := rootEngine.LoadFromIR(loadContext, filename, rulesdata.PrecompiledRules); err != nil {
- panic(fmt.Sprintf("load embedded ruleguard rules: %v", err))
+ return fmt.Errorf("load embedded ruleguard rules: %w", err)
}
groups = rootEngine.LoadedGroups()
}
@@ -87,6 +87,8 @@ func InitEmbeddedRules() {
return c, nil
})
}
+
+ return nil
}
type embeddedRuleguardChecker struct {
diff --git a/vendor/github.com/go-critic/go-critic/checkers/hugeParam_checker.go b/vendor/github.com/go-critic/go-critic/checkers/hugeParam_checker.go
index 910be180b..742652a12 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/hugeParam_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/hugeParam_checker.go
@@ -5,7 +5,6 @@ import (
"github.com/go-critic/go-critic/checkers/internal/astwalk"
"github.com/go-critic/go-critic/framework/linter"
- "golang.org/x/exp/typeparams"
)
func init() {
@@ -50,9 +49,6 @@ func (c *hugeParamChecker) checkParams(params []*ast.Field) {
for _, p := range params {
for _, id := range p.Names {
typ := c.ctx.TypeOf(id)
- if _, ok := typ.(*typeparams.TypeParam); ok {
- continue
- }
size, ok := c.ctx.SizeOf(typ)
if ok && size >= c.sizeThreshold {
c.warn(id, size)
diff --git a/vendor/github.com/go-critic/go-critic/checkers/ifElseChain_checker.go b/vendor/github.com/go-critic/go-critic/checkers/ifElseChain_checker.go
index b1fcf4147..c3d127c56 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/ifElseChain_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/ifElseChain_checker.go
@@ -11,6 +11,12 @@ func init() {
var info linter.CheckerInfo
info.Name = "ifElseChain"
info.Tags = []string{"style"}
+ info.Params = linter.CheckerParams{
+ "minThreshold": {
+ Value: 2,
+ Usage: "min number of if-else blocks that makes the warning trigger",
+ },
+ }
info.Summary = "Detects repeated if-else statements and suggests to replace them with switch statement"
info.Before = `
if cond1 {
@@ -35,7 +41,10 @@ will trigger suggestion to use switch statement.
See [EffectiveGo#switch](https://golang.org/doc/effective_go.html#switch).`
collection.AddChecker(&info, func(ctx *linter.CheckerContext) (linter.FileWalker, error) {
- return astwalk.WalkerForStmt(&ifElseChainChecker{ctx: ctx}), nil
+ return astwalk.WalkerForStmt(&ifElseChainChecker{
+ ctx: ctx,
+ minThreshold: info.Params.Int("minThreshold"),
+ }), nil
})
}
@@ -45,6 +54,8 @@ type ifElseChainChecker struct {
cause *ast.IfStmt
visited map[*ast.IfStmt]bool
+
+ minThreshold int
}
func (c *ifElseChainChecker) EnterFunc(fn *ast.FuncDecl) bool {
@@ -66,8 +77,7 @@ func (c *ifElseChainChecker) VisitStmt(stmt ast.Stmt) {
}
func (c *ifElseChainChecker) checkIfStmt(stmt *ast.IfStmt) {
- const minThreshold = 2
- if c.countIfelseLen(stmt) >= minThreshold {
+ if c.countIfelseLen(stmt) >= c.minThreshold {
c.warn()
}
}
@@ -75,11 +85,12 @@ func (c *ifElseChainChecker) checkIfStmt(stmt *ast.IfStmt) {
func (c *ifElseChainChecker) countIfelseLen(stmt *ast.IfStmt) int {
count := 0
for {
+ if stmt.Init != nil {
+ return 0 // Give up
+ }
+
switch e := stmt.Else.(type) {
case *ast.IfStmt:
- if e.Init != nil {
- return 0 // Give up
- }
// Else if.
stmt = e
count++
diff --git a/vendor/github.com/go-critic/go-critic/checkers/internal/astwalk/local_def_visitor.go b/vendor/github.com/go-critic/go-critic/checkers/internal/astwalk/local_def_visitor.go
index 47de589a4..5fcce6a2a 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/internal/astwalk/local_def_visitor.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/internal/astwalk/local_def_visitor.go
@@ -7,9 +7,9 @@ import (
// LocalDefVisitor visits every name definitions inside a function.
//
// Next elements are considered as name definitions:
-// - Function parameters (input, output, receiver)
-// - Every LHS of ":=" assignment that defines a new name
-// - Every local var/const declaration.
+// - Function parameters (input, output, receiver)
+// - Every LHS of ":=" assignment that defines a new name
+// - Every local var/const declaration.
//
// NOTE: this visitor is experimental.
// This is also why it lives in a separate file.
diff --git a/vendor/github.com/go-critic/go-critic/checkers/internal/astwalk/type_expr_walker.go b/vendor/github.com/go-critic/go-critic/checkers/internal/astwalk/type_expr_walker.go
index 9c198e733..bc9bdef47 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/internal/astwalk/type_expr_walker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/internal/astwalk/type_expr_walker.go
@@ -97,7 +97,10 @@ func (w *typeExprWalker) walk(x ast.Node) bool {
func (w *typeExprWalker) inspectInner(x ast.Expr) bool {
parens, ok := x.(*ast.ParenExpr)
- if ok && typep.IsTypeExpr(w.info, parens.X) && astp.IsStarExpr(parens.X) {
+ shouldInspect := ok &&
+ typep.IsTypeExpr(w.info, parens.X) &&
+ (astp.IsStarExpr(parens.X) || astp.IsFuncType(parens.X))
+ if shouldInspect {
ast.Inspect(parens.X, w.walk)
return false
}
diff --git a/vendor/github.com/go-critic/go-critic/checkers/newDeref_checker.go b/vendor/github.com/go-critic/go-critic/checkers/newDeref_checker.go
index 7e564b70f..04a3474f9 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/newDeref_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/newDeref_checker.go
@@ -7,6 +7,7 @@ import (
"github.com/go-critic/go-critic/checkers/internal/lintutil"
"github.com/go-critic/go-critic/framework/linter"
"github.com/go-toolsmith/astcast"
+ "golang.org/x/exp/typeparams"
"golang.org/x/tools/go/ast/astutil"
)
@@ -33,6 +34,10 @@ func (c *newDerefChecker) VisitExpr(expr ast.Expr) {
call := astcast.ToCallExpr(deref.X)
if astcast.ToIdent(call.Fun).Name == "new" {
typ := c.ctx.TypeOf(call.Args[0])
+ // allow *new(T) if T is a type parameter, see #1272 for details
+ if typeparams.IsTypeParam(typ) {
+ return
+ }
zv := lintutil.ZeroValueOf(astutil.Unparen(call.Args[0]), typ)
if zv != nil {
c.warn(expr, zv)
diff --git a/vendor/github.com/go-critic/go-critic/checkers/rangeValCopy_checker.go b/vendor/github.com/go-critic/go-critic/checkers/rangeValCopy_checker.go
index eafc549d6..37f469657 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/rangeValCopy_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/rangeValCopy_checker.go
@@ -5,7 +5,6 @@ import (
"github.com/go-critic/go-critic/checkers/internal/astwalk"
"github.com/go-critic/go-critic/framework/linter"
- "golang.org/x/exp/typeparams"
)
func init() {
@@ -66,10 +65,8 @@ func (c *rangeValCopyChecker) VisitStmt(stmt ast.Stmt) {
if typ == nil {
return
}
- if _, ok := typ.(*typeparams.TypeParam); ok {
- return
- }
- if size, ok := c.ctx.SizeOf(typ); ok && size >= c.sizeThreshold {
+ size, ok := c.ctx.SizeOf(typ)
+ if ok && size >= c.sizeThreshold {
c.warn(rng, size)
}
}
diff --git a/vendor/github.com/go-critic/go-critic/checkers/ruleguard_checker.go b/vendor/github.com/go-critic/go-critic/checkers/ruleguard_checker.go
index 35c6a6449..000007a31 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/ruleguard_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/ruleguard_checker.go
@@ -274,7 +274,7 @@ func (c *ruleguardChecker) WalkFile(f *ast.File) {
func runRuleguardEngine(ctx *linter.CheckerContext, f *ast.File, e *ruleguard.Engine, runCtx *ruleguard.RunContext) {
type ruleguardReport struct {
- node ast.Node
+ pos token.Pos
message string
fix linter.QuickFix
}
@@ -284,7 +284,7 @@ func runRuleguardEngine(ctx *linter.CheckerContext, f *ast.File, e *ruleguard.En
// TODO(quasilyte): investigate whether we should add a rule name as
// a message prefix here.
r := ruleguardReport{
- node: data.Node,
+ pos: data.Node.Pos(),
message: data.Message,
}
fix := data.Suggestion
@@ -310,9 +310,9 @@ func runRuleguardEngine(ctx *linter.CheckerContext, f *ast.File, e *ruleguard.En
})
for _, report := range reports {
if report.fix.Replacement != nil {
- ctx.WarnFixable(report.node, report.fix, "%s", report.message)
+ ctx.WarnFixableWithPos(report.pos, report.fix, "%s", report.message)
} else {
- ctx.Warn(report.node, "%s", report.message)
+ ctx.WarnWithPos(report.pos, "%s", report.message)
}
}
}
diff --git a/vendor/github.com/go-critic/go-critic/checkers/rulesdata/rulesdata.go b/vendor/github.com/go-critic/go-critic/checkers/rulesdata/rulesdata.go
index fd63c9b14..f0b147a68 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/rulesdata/rulesdata.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/rulesdata/rulesdata.go
@@ -28,11 +28,30 @@ var PrecompiledRules = &ir.File{
ReportTemplate: "use $x.String() instead",
SuggestTemplate: "$x.String()",
WhereExpr: ir.FilterExpr{
- Line: 13,
- Op: ir.FilterVarTypeImplementsOp,
- Src: "m[\"x\"].Type.Implements(`fmt.Stringer`)",
- Value: "x",
- Args: []ir.FilterExpr{{Line: 13, Op: ir.FilterStringOp, Src: "`fmt.Stringer`", Value: "fmt.Stringer"}},
+ Line: 13,
+ Op: ir.FilterAndOp,
+ Src: "!m[\"x\"].Type.Is(`reflect.Value`) && m[\"x\"].Type.Implements(`fmt.Stringer`)",
+ Args: []ir.FilterExpr{
+ {
+ Line: 13,
+ Op: ir.FilterNotOp,
+ Src: "!m[\"x\"].Type.Is(`reflect.Value`)",
+ Args: []ir.FilterExpr{{
+ Line: 13,
+ Op: ir.FilterVarTypeIsOp,
+ Src: "m[\"x\"].Type.Is(`reflect.Value`)",
+ Value: "x",
+ Args: []ir.FilterExpr{{Line: 13, Op: ir.FilterStringOp, Src: "`reflect.Value`", Value: "reflect.Value"}},
+ }},
+ },
+ {
+ Line: 13,
+ Op: ir.FilterVarTypeImplementsOp,
+ Src: "m[\"x\"].Type.Implements(`fmt.Stringer`)",
+ Value: "x",
+ Args: []ir.FilterExpr{{Line: 13, Op: ir.FilterStringOp, Src: "`fmt.Stringer`", Value: "fmt.Stringer"}},
+ },
+ },
},
},
{
@@ -379,28 +398,26 @@ var PrecompiledRules = &ir.File{
{Line: 119, Op: ir.FilterStringOp, Src: "\"nil\"", Value: "nil"},
},
},
- LocationVar: "nil",
},
{
- Line: 124,
- SyntaxPatterns: []ir.PatternString{{Line: 124, Value: "http.NewRequestWithContext($ctx, $method, $url, $nil)"}},
+ Line: 123,
+ SyntaxPatterns: []ir.PatternString{{Line: 123, Value: "http.NewRequestWithContext($ctx, $method, $url, $nil)"}},
ReportTemplate: "http.NoBody should be preferred to the nil request body",
SuggestTemplate: "http.NewRequestWithContext($ctx, $method, $url, http.NoBody)",
WhereExpr: ir.FilterExpr{
- Line: 125,
+ Line: 124,
Op: ir.FilterEqOp,
Src: "m[\"nil\"].Text == \"nil\"",
Args: []ir.FilterExpr{
- {Line: 125, Op: ir.FilterVarTextOp, Src: "m[\"nil\"].Text", Value: "nil"},
- {Line: 125, Op: ir.FilterStringOp, Src: "\"nil\"", Value: "nil"},
+ {Line: 124, Op: ir.FilterVarTextOp, Src: "m[\"nil\"].Text", Value: "nil"},
+ {Line: 124, Op: ir.FilterStringOp, Src: "\"nil\"", Value: "nil"},
},
},
- LocationVar: "nil",
},
},
},
{
- Line: 136,
+ Line: 134,
Name: "preferDecodeRune",
MatcherName: "m",
DocTags: []string{"performance", "experimental"},
@@ -409,20 +426,20 @@ var PrecompiledRules = &ir.File{
DocAfter: "r, _ := utf8.DecodeRuneInString(s)",
DocNote: "See Go issue for details: https://github.com/golang/go/issues/45260",
Rules: []ir.Rule{{
- Line: 137,
- SyntaxPatterns: []ir.PatternString{{Line: 137, Value: "[]rune($s)[0]"}},
+ Line: 135,
+ SyntaxPatterns: []ir.PatternString{{Line: 135, Value: "[]rune($s)[0]"}},
ReportTemplate: "consider replacing $$ with utf8.DecodeRuneInString($s)",
WhereExpr: ir.FilterExpr{
- Line: 138,
+ Line: 136,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`string`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 138, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 136, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
}},
},
{
- Line: 146,
+ Line: 144,
Name: "sloppyLen",
MatcherName: "m",
DocTags: []string{"style"},
@@ -431,24 +448,24 @@ var PrecompiledRules = &ir.File{
DocAfter: "len(arr) == 0",
Rules: []ir.Rule{
{
- Line: 147,
- SyntaxPatterns: []ir.PatternString{{Line: 147, Value: "len($_) >= 0"}},
+ Line: 145,
+ SyntaxPatterns: []ir.PatternString{{Line: 145, Value: "len($_) >= 0"}},
ReportTemplate: "$$ is always true",
},
{
- Line: 148,
- SyntaxPatterns: []ir.PatternString{{Line: 148, Value: "len($_) < 0"}},
+ Line: 146,
+ SyntaxPatterns: []ir.PatternString{{Line: 146, Value: "len($_) < 0"}},
ReportTemplate: "$$ is always false",
},
{
- Line: 149,
- SyntaxPatterns: []ir.PatternString{{Line: 149, Value: "len($x) <= 0"}},
+ Line: 147,
+ SyntaxPatterns: []ir.PatternString{{Line: 147, Value: "len($x) <= 0"}},
ReportTemplate: "$$ can be len($x) == 0",
},
},
},
{
- Line: 156,
+ Line: 154,
Name: "valSwap",
MatcherName: "m",
DocTags: []string{"style"},
@@ -456,13 +473,13 @@ var PrecompiledRules = &ir.File{
DocBefore: "*tmp = *x; *x = *y; *y = *tmp",
DocAfter: "*x, *y = *y, *x",
Rules: []ir.Rule{{
- Line: 157,
- SyntaxPatterns: []ir.PatternString{{Line: 157, Value: "$tmp := $y; $y = $x; $x = $tmp"}},
+ Line: 155,
+ SyntaxPatterns: []ir.PatternString{{Line: 155, Value: "$tmp := $y; $y = $x; $x = $tmp"}},
ReportTemplate: "can re-write as `$y, $x = $x, $y`",
}},
},
{
- Line: 165,
+ Line: 163,
Name: "switchTrue",
MatcherName: "m",
DocTags: []string{"style"},
@@ -471,19 +488,19 @@ var PrecompiledRules = &ir.File{
DocAfter: "switch {...}",
Rules: []ir.Rule{
{
- Line: 166,
- SyntaxPatterns: []ir.PatternString{{Line: 166, Value: "switch true { $*_ }"}},
+ Line: 164,
+ SyntaxPatterns: []ir.PatternString{{Line: 164, Value: "switch true { $*_ }"}},
ReportTemplate: "replace 'switch true {}' with 'switch {}'",
},
{
- Line: 168,
- SyntaxPatterns: []ir.PatternString{{Line: 168, Value: "switch $x; true { $*_ }"}},
+ Line: 166,
+ SyntaxPatterns: []ir.PatternString{{Line: 166, Value: "switch $x; true { $*_ }"}},
ReportTemplate: "replace 'switch $x; true {}' with 'switch $x; {}'",
},
},
},
{
- Line: 176,
+ Line: 174,
Name: "flagDeref",
MatcherName: "m",
DocTags: []string{"diagnostic"},
@@ -492,49 +509,49 @@ var PrecompiledRules = &ir.File{
DocAfter: "var b bool; flag.BoolVar(&b, \"b\", false, \"b docs\")",
Rules: []ir.Rule{
{
- Line: 177,
- SyntaxPatterns: []ir.PatternString{{Line: 177, Value: "*flag.Bool($*_)"}},
+ Line: 175,
+ SyntaxPatterns: []ir.PatternString{{Line: 175, Value: "*flag.Bool($*_)"}},
ReportTemplate: "immediate deref in $$ is most likely an error; consider using flag.BoolVar",
},
{
- Line: 178,
- SyntaxPatterns: []ir.PatternString{{Line: 178, Value: "*flag.Duration($*_)"}},
+ Line: 176,
+ SyntaxPatterns: []ir.PatternString{{Line: 176, Value: "*flag.Duration($*_)"}},
ReportTemplate: "immediate deref in $$ is most likely an error; consider using flag.DurationVar",
},
{
- Line: 179,
- SyntaxPatterns: []ir.PatternString{{Line: 179, Value: "*flag.Float64($*_)"}},
+ Line: 177,
+ SyntaxPatterns: []ir.PatternString{{Line: 177, Value: "*flag.Float64($*_)"}},
ReportTemplate: "immediate deref in $$ is most likely an error; consider using flag.Float64Var",
},
{
- Line: 180,
- SyntaxPatterns: []ir.PatternString{{Line: 180, Value: "*flag.Int($*_)"}},
+ Line: 178,
+ SyntaxPatterns: []ir.PatternString{{Line: 178, Value: "*flag.Int($*_)"}},
ReportTemplate: "immediate deref in $$ is most likely an error; consider using flag.IntVar",
},
{
- Line: 181,
- SyntaxPatterns: []ir.PatternString{{Line: 181, Value: "*flag.Int64($*_)"}},
+ Line: 179,
+ SyntaxPatterns: []ir.PatternString{{Line: 179, Value: "*flag.Int64($*_)"}},
ReportTemplate: "immediate deref in $$ is most likely an error; consider using flag.Int64Var",
},
{
- Line: 182,
- SyntaxPatterns: []ir.PatternString{{Line: 182, Value: "*flag.String($*_)"}},
+ Line: 180,
+ SyntaxPatterns: []ir.PatternString{{Line: 180, Value: "*flag.String($*_)"}},
ReportTemplate: "immediate deref in $$ is most likely an error; consider using flag.StringVar",
},
{
- Line: 183,
- SyntaxPatterns: []ir.PatternString{{Line: 183, Value: "*flag.Uint($*_)"}},
+ Line: 181,
+ SyntaxPatterns: []ir.PatternString{{Line: 181, Value: "*flag.Uint($*_)"}},
ReportTemplate: "immediate deref in $$ is most likely an error; consider using flag.UintVar",
},
{
- Line: 184,
- SyntaxPatterns: []ir.PatternString{{Line: 184, Value: "*flag.Uint64($*_)"}},
+ Line: 182,
+ SyntaxPatterns: []ir.PatternString{{Line: 182, Value: "*flag.Uint64($*_)"}},
ReportTemplate: "immediate deref in $$ is most likely an error; consider using flag.Uint64Var",
},
},
},
{
- Line: 191,
+ Line: 189,
Name: "emptyStringTest",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -543,33 +560,33 @@ var PrecompiledRules = &ir.File{
DocAfter: "s == \"\"",
Rules: []ir.Rule{
{
- Line: 192,
- SyntaxPatterns: []ir.PatternString{{Line: 192, Value: "len($s) != 0"}},
+ Line: 190,
+ SyntaxPatterns: []ir.PatternString{{Line: 190, Value: "len($s) != 0"}},
ReportTemplate: "replace `$$` with `$s != \"\"`",
WhereExpr: ir.FilterExpr{
- Line: 193,
+ Line: 191,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`string`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 193, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 191, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
},
{
- Line: 196,
- SyntaxPatterns: []ir.PatternString{{Line: 196, Value: "len($s) == 0"}},
+ Line: 194,
+ SyntaxPatterns: []ir.PatternString{{Line: 194, Value: "len($s) == 0"}},
ReportTemplate: "replace `$$` with `$s == \"\"`",
WhereExpr: ir.FilterExpr{
- Line: 197,
+ Line: 195,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`string`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 197, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 195, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
},
},
},
{
- Line: 205,
+ Line: 203,
Name: "stringXbytes",
MatcherName: "m",
DocTags: []string{"performance"},
@@ -578,180 +595,180 @@ var PrecompiledRules = &ir.File{
DocAfter: "copy(b, s)",
Rules: []ir.Rule{
{
- Line: 206,
- SyntaxPatterns: []ir.PatternString{{Line: 206, Value: "copy($_, []byte($s))"}},
+ Line: 204,
+ SyntaxPatterns: []ir.PatternString{{Line: 204, Value: "copy($_, []byte($s))"}},
ReportTemplate: "can simplify `[]byte($s)` to `$s`",
},
{
- Line: 208,
- SyntaxPatterns: []ir.PatternString{{Line: 208, Value: "string($b) == \"\""}},
+ Line: 206,
+ SyntaxPatterns: []ir.PatternString{{Line: 206, Value: "string($b) == \"\""}},
ReportTemplate: "suggestion: len($b) == 0",
SuggestTemplate: "len($b) == 0",
WhereExpr: ir.FilterExpr{
- Line: 208,
+ Line: 206,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"b\"].Type.Is(`[]byte`)",
Value: "b",
- Args: []ir.FilterExpr{{Line: 208, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 206, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
},
{
- Line: 209,
- SyntaxPatterns: []ir.PatternString{{Line: 209, Value: "string($b) != \"\""}},
+ Line: 207,
+ SyntaxPatterns: []ir.PatternString{{Line: 207, Value: "string($b) != \"\""}},
ReportTemplate: "suggestion: len($b) != 0",
SuggestTemplate: "len($b) != 0",
WhereExpr: ir.FilterExpr{
- Line: 209,
+ Line: 207,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"b\"].Type.Is(`[]byte`)",
Value: "b",
- Args: []ir.FilterExpr{{Line: 209, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 207, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
},
{
- Line: 211,
- SyntaxPatterns: []ir.PatternString{{Line: 211, Value: "len(string($b))"}},
+ Line: 209,
+ SyntaxPatterns: []ir.PatternString{{Line: 209, Value: "len(string($b))"}},
ReportTemplate: "suggestion: len($b)",
SuggestTemplate: "len($b)",
WhereExpr: ir.FilterExpr{
- Line: 211,
+ Line: 209,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"b\"].Type.Is(`[]byte`)",
Value: "b",
- Args: []ir.FilterExpr{{Line: 211, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 209, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
},
{
- Line: 213,
- SyntaxPatterns: []ir.PatternString{{Line: 213, Value: "string($x) == string($y)"}},
+ Line: 211,
+ SyntaxPatterns: []ir.PatternString{{Line: 211, Value: "string($x) == string($y)"}},
ReportTemplate: "suggestion: bytes.Equal($x, $y)",
SuggestTemplate: "bytes.Equal($x, $y)",
WhereExpr: ir.FilterExpr{
- Line: 214,
+ Line: 212,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Type.Is(`[]byte`) && m[\"y\"].Type.Is(`[]byte`)",
Args: []ir.FilterExpr{
{
- Line: 214,
+ Line: 212,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`[]byte`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 214, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 212, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
{
- Line: 214,
+ Line: 212,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"y\"].Type.Is(`[]byte`)",
Value: "y",
- Args: []ir.FilterExpr{{Line: 214, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 212, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
},
},
},
{
- Line: 217,
- SyntaxPatterns: []ir.PatternString{{Line: 217, Value: "string($x) != string($y)"}},
+ Line: 215,
+ SyntaxPatterns: []ir.PatternString{{Line: 215, Value: "string($x) != string($y)"}},
ReportTemplate: "suggestion: !bytes.Equal($x, $y)",
SuggestTemplate: "!bytes.Equal($x, $y)",
WhereExpr: ir.FilterExpr{
- Line: 218,
+ Line: 216,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Type.Is(`[]byte`) && m[\"y\"].Type.Is(`[]byte`)",
Args: []ir.FilterExpr{
{
- Line: 218,
+ Line: 216,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`[]byte`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 218, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 216, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
{
- Line: 218,
+ Line: 216,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"y\"].Type.Is(`[]byte`)",
Value: "y",
- Args: []ir.FilterExpr{{Line: 218, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 216, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
},
},
},
{
- Line: 221,
- SyntaxPatterns: []ir.PatternString{{Line: 221, Value: "$re.Match([]byte($s))"}},
+ Line: 219,
+ SyntaxPatterns: []ir.PatternString{{Line: 219, Value: "$re.Match([]byte($s))"}},
ReportTemplate: "suggestion: $re.MatchString($s)",
SuggestTemplate: "$re.MatchString($s)",
WhereExpr: ir.FilterExpr{
- Line: 222,
+ Line: 220,
Op: ir.FilterAndOp,
Src: "m[\"re\"].Type.Is(`*regexp.Regexp`) && m[\"s\"].Type.Is(`string`)",
Args: []ir.FilterExpr{
{
- Line: 222,
+ Line: 220,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"re\"].Type.Is(`*regexp.Regexp`)",
Value: "re",
- Args: []ir.FilterExpr{{Line: 222, Op: ir.FilterStringOp, Src: "`*regexp.Regexp`", Value: "*regexp.Regexp"}},
+ Args: []ir.FilterExpr{{Line: 220, Op: ir.FilterStringOp, Src: "`*regexp.Regexp`", Value: "*regexp.Regexp"}},
},
{
- Line: 222,
+ Line: 220,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`string`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 222, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 220, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
},
},
},
{
- Line: 225,
- SyntaxPatterns: []ir.PatternString{{Line: 225, Value: "$re.FindIndex([]byte($s))"}},
+ Line: 223,
+ SyntaxPatterns: []ir.PatternString{{Line: 223, Value: "$re.FindIndex([]byte($s))"}},
ReportTemplate: "suggestion: $re.FindStringIndex($s)",
SuggestTemplate: "$re.FindStringIndex($s)",
WhereExpr: ir.FilterExpr{
- Line: 226,
+ Line: 224,
Op: ir.FilterAndOp,
Src: "m[\"re\"].Type.Is(`*regexp.Regexp`) && m[\"s\"].Type.Is(`string`)",
Args: []ir.FilterExpr{
{
- Line: 226,
+ Line: 224,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"re\"].Type.Is(`*regexp.Regexp`)",
Value: "re",
- Args: []ir.FilterExpr{{Line: 226, Op: ir.FilterStringOp, Src: "`*regexp.Regexp`", Value: "*regexp.Regexp"}},
+ Args: []ir.FilterExpr{{Line: 224, Op: ir.FilterStringOp, Src: "`*regexp.Regexp`", Value: "*regexp.Regexp"}},
},
{
- Line: 226,
+ Line: 224,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`string`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 226, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 224, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
},
},
},
{
- Line: 229,
- SyntaxPatterns: []ir.PatternString{{Line: 229, Value: "$re.FindAllIndex([]byte($s), $n)"}},
+ Line: 227,
+ SyntaxPatterns: []ir.PatternString{{Line: 227, Value: "$re.FindAllIndex([]byte($s), $n)"}},
ReportTemplate: "suggestion: $re.FindAllStringIndex($s, $n)",
SuggestTemplate: "$re.FindAllStringIndex($s, $n)",
WhereExpr: ir.FilterExpr{
- Line: 230,
+ Line: 228,
Op: ir.FilterAndOp,
Src: "m[\"re\"].Type.Is(`*regexp.Regexp`) && m[\"s\"].Type.Is(`string`)",
Args: []ir.FilterExpr{
{
- Line: 230,
+ Line: 228,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"re\"].Type.Is(`*regexp.Regexp`)",
Value: "re",
- Args: []ir.FilterExpr{{Line: 230, Op: ir.FilterStringOp, Src: "`*regexp.Regexp`", Value: "*regexp.Regexp"}},
+ Args: []ir.FilterExpr{{Line: 228, Op: ir.FilterStringOp, Src: "`*regexp.Regexp`", Value: "*regexp.Regexp"}},
},
{
- Line: 230,
+ Line: 228,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`string`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 230, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 228, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
},
},
@@ -759,7 +776,7 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 239,
+ Line: 237,
Name: "indexAlloc",
MatcherName: "m",
DocTags: []string{"performance"},
@@ -768,22 +785,22 @@ var PrecompiledRules = &ir.File{
DocAfter: "bytes.Index(x, []byte(y))",
DocNote: "See Go issue for details: https://github.com/golang/go/issues/25864",
Rules: []ir.Rule{{
- Line: 240,
- SyntaxPatterns: []ir.PatternString{{Line: 240, Value: "strings.Index(string($x), $y)"}},
+ Line: 238,
+ SyntaxPatterns: []ir.PatternString{{Line: 238, Value: "strings.Index(string($x), $y)"}},
ReportTemplate: "consider replacing $$ with bytes.Index($x, []byte($y))",
WhereExpr: ir.FilterExpr{
- Line: 241,
+ Line: 239,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure",
Args: []ir.FilterExpr{
- {Line: 241, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
- {Line: 241, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
+ {Line: 239, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ {Line: 239, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
},
},
}},
},
{
- Line: 249,
+ Line: 247,
Name: "wrapperFunc",
MatcherName: "m",
DocTags: []string{"style"},
@@ -792,83 +809,83 @@ var PrecompiledRules = &ir.File{
DocAfter: "wg.Done()",
Rules: []ir.Rule{
{
- Line: 250,
- SyntaxPatterns: []ir.PatternString{{Line: 250, Value: "$wg.Add(-1)"}},
+ Line: 248,
+ SyntaxPatterns: []ir.PatternString{{Line: 248, Value: "$wg.Add(-1)"}},
ReportTemplate: "use WaitGroup.Done method in `$$`",
WhereExpr: ir.FilterExpr{
- Line: 251,
+ Line: 249,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"wg\"].Type.Is(`sync.WaitGroup`)",
Value: "wg",
- Args: []ir.FilterExpr{{Line: 251, Op: ir.FilterStringOp, Src: "`sync.WaitGroup`", Value: "sync.WaitGroup"}},
+ Args: []ir.FilterExpr{{Line: 249, Op: ir.FilterStringOp, Src: "`sync.WaitGroup`", Value: "sync.WaitGroup"}},
},
},
{
- Line: 254,
- SyntaxPatterns: []ir.PatternString{{Line: 254, Value: "$buf.Truncate(0)"}},
+ Line: 252,
+ SyntaxPatterns: []ir.PatternString{{Line: 252, Value: "$buf.Truncate(0)"}},
ReportTemplate: "use Buffer.Reset method in `$$`",
WhereExpr: ir.FilterExpr{
- Line: 255,
+ Line: 253,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"buf\"].Type.Is(`bytes.Buffer`)",
Value: "buf",
- Args: []ir.FilterExpr{{Line: 255, Op: ir.FilterStringOp, Src: "`bytes.Buffer`", Value: "bytes.Buffer"}},
+ Args: []ir.FilterExpr{{Line: 253, Op: ir.FilterStringOp, Src: "`bytes.Buffer`", Value: "bytes.Buffer"}},
},
},
{
- Line: 258,
- SyntaxPatterns: []ir.PatternString{{Line: 258, Value: "http.HandlerFunc(http.NotFound)"}},
+ Line: 256,
+ SyntaxPatterns: []ir.PatternString{{Line: 256, Value: "http.HandlerFunc(http.NotFound)"}},
ReportTemplate: "use http.NotFoundHandler method in `$$`",
},
{
- Line: 260,
- SyntaxPatterns: []ir.PatternString{{Line: 260, Value: "strings.SplitN($_, $_, -1)"}},
+ Line: 258,
+ SyntaxPatterns: []ir.PatternString{{Line: 258, Value: "strings.SplitN($_, $_, -1)"}},
ReportTemplate: "use strings.Split method in `$$`",
},
{
- Line: 261,
- SyntaxPatterns: []ir.PatternString{{Line: 261, Value: "strings.Replace($_, $_, $_, -1)"}},
+ Line: 259,
+ SyntaxPatterns: []ir.PatternString{{Line: 259, Value: "strings.Replace($_, $_, $_, -1)"}},
ReportTemplate: "use strings.ReplaceAll method in `$$`",
},
{
- Line: 262,
- SyntaxPatterns: []ir.PatternString{{Line: 262, Value: "strings.Map(unicode.ToTitle, $_)"}},
+ Line: 260,
+ SyntaxPatterns: []ir.PatternString{{Line: 260, Value: "strings.Map(unicode.ToTitle, $_)"}},
ReportTemplate: "use strings.ToTitle method in `$$`",
},
{
- Line: 264,
- SyntaxPatterns: []ir.PatternString{{Line: 264, Value: "bytes.SplitN(b, []byte(\".\"), -1)"}},
+ Line: 262,
+ SyntaxPatterns: []ir.PatternString{{Line: 262, Value: "bytes.SplitN(b, []byte(\".\"), -1)"}},
ReportTemplate: "use bytes.Split method in `$$`",
},
{
- Line: 265,
- SyntaxPatterns: []ir.PatternString{{Line: 265, Value: "bytes.Replace($_, $_, $_, -1)"}},
+ Line: 263,
+ SyntaxPatterns: []ir.PatternString{{Line: 263, Value: "bytes.Replace($_, $_, $_, -1)"}},
ReportTemplate: "use bytes.ReplaceAll method in `$$`",
},
{
- Line: 266,
- SyntaxPatterns: []ir.PatternString{{Line: 266, Value: "bytes.Map(unicode.ToUpper, $_)"}},
+ Line: 264,
+ SyntaxPatterns: []ir.PatternString{{Line: 264, Value: "bytes.Map(unicode.ToUpper, $_)"}},
ReportTemplate: "use bytes.ToUpper method in `$$`",
},
{
- Line: 267,
- SyntaxPatterns: []ir.PatternString{{Line: 267, Value: "bytes.Map(unicode.ToLower, $_)"}},
+ Line: 265,
+ SyntaxPatterns: []ir.PatternString{{Line: 265, Value: "bytes.Map(unicode.ToLower, $_)"}},
ReportTemplate: "use bytes.ToLower method in `$$`",
},
{
- Line: 268,
- SyntaxPatterns: []ir.PatternString{{Line: 268, Value: "bytes.Map(unicode.ToTitle, $_)"}},
+ Line: 266,
+ SyntaxPatterns: []ir.PatternString{{Line: 266, Value: "bytes.Map(unicode.ToTitle, $_)"}},
ReportTemplate: "use bytes.ToTitle method in `$$`",
},
{
- Line: 270,
- SyntaxPatterns: []ir.PatternString{{Line: 270, Value: "draw.DrawMask($_, $_, $_, $_, nil, image.Point{}, $_)"}},
+ Line: 268,
+ SyntaxPatterns: []ir.PatternString{{Line: 268, Value: "draw.DrawMask($_, $_, $_, $_, nil, image.Point{}, $_)"}},
ReportTemplate: "use draw.Draw method in `$$`",
},
},
},
{
- Line: 278,
+ Line: 276,
Name: "regexpMust",
MatcherName: "m",
DocTags: []string{"style"},
@@ -877,22 +894,22 @@ var PrecompiledRules = &ir.File{
DocAfter: "re := regexp.MustCompile(\"const pattern\")",
Rules: []ir.Rule{
{
- Line: 279,
- SyntaxPatterns: []ir.PatternString{{Line: 279, Value: "regexp.Compile($pat)"}},
+ Line: 277,
+ SyntaxPatterns: []ir.PatternString{{Line: 277, Value: "regexp.Compile($pat)"}},
ReportTemplate: "for const patterns like $pat, use regexp.MustCompile",
WhereExpr: ir.FilterExpr{
- Line: 280,
+ Line: 278,
Op: ir.FilterVarConstOp,
Src: "m[\"pat\"].Const",
Value: "pat",
},
},
{
- Line: 283,
- SyntaxPatterns: []ir.PatternString{{Line: 283, Value: "regexp.CompilePOSIX($pat)"}},
+ Line: 281,
+ SyntaxPatterns: []ir.PatternString{{Line: 281, Value: "regexp.CompilePOSIX($pat)"}},
ReportTemplate: "for const patterns like $pat, use regexp.MustCompilePOSIX",
WhereExpr: ir.FilterExpr{
- Line: 284,
+ Line: 282,
Op: ir.FilterVarConstOp,
Src: "m[\"pat\"].Const",
Value: "pat",
@@ -901,7 +918,7 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 292,
+ Line: 290,
Name: "badCall",
MatcherName: "m",
DocTags: []string{"diagnostic"},
@@ -910,22 +927,22 @@ var PrecompiledRules = &ir.File{
DocAfter: "strings.Replace(s, from, to, -1)",
Rules: []ir.Rule{
{
- Line: 293,
- SyntaxPatterns: []ir.PatternString{{Line: 293, Value: "strings.Replace($_, $_, $_, $zero)"}},
+ Line: 291,
+ SyntaxPatterns: []ir.PatternString{{Line: 291, Value: "strings.Replace($_, $_, $_, $zero)"}},
ReportTemplate: "suspicious arg 0, probably meant -1",
WhereExpr: ir.FilterExpr{
- Line: 294,
+ Line: 292,
Op: ir.FilterEqOp,
Src: "m[\"zero\"].Value.Int() == 0",
Args: []ir.FilterExpr{
{
- Line: 294,
+ Line: 292,
Op: ir.FilterVarValueIntOp,
Src: "m[\"zero\"].Value.Int()",
Value: "zero",
},
{
- Line: 294,
+ Line: 292,
Op: ir.FilterIntOp,
Src: "0",
Value: int64(0),
@@ -935,22 +952,22 @@ var PrecompiledRules = &ir.File{
LocationVar: "zero",
},
{
- Line: 296,
- SyntaxPatterns: []ir.PatternString{{Line: 296, Value: "bytes.Replace($_, $_, $_, $zero)"}},
+ Line: 294,
+ SyntaxPatterns: []ir.PatternString{{Line: 294, Value: "bytes.Replace($_, $_, $_, $zero)"}},
ReportTemplate: "suspicious arg 0, probably meant -1",
WhereExpr: ir.FilterExpr{
- Line: 297,
+ Line: 295,
Op: ir.FilterEqOp,
Src: "m[\"zero\"].Value.Int() == 0",
Args: []ir.FilterExpr{
{
- Line: 297,
+ Line: 295,
Op: ir.FilterVarValueIntOp,
Src: "m[\"zero\"].Value.Int()",
Value: "zero",
},
{
- Line: 297,
+ Line: 295,
Op: ir.FilterIntOp,
Src: "0",
Value: int64(0),
@@ -960,22 +977,22 @@ var PrecompiledRules = &ir.File{
LocationVar: "zero",
},
{
- Line: 300,
- SyntaxPatterns: []ir.PatternString{{Line: 300, Value: "strings.SplitN($_, $_, $zero)"}},
+ Line: 298,
+ SyntaxPatterns: []ir.PatternString{{Line: 298, Value: "strings.SplitN($_, $_, $zero)"}},
ReportTemplate: "suspicious arg 0, probably meant -1",
WhereExpr: ir.FilterExpr{
- Line: 301,
+ Line: 299,
Op: ir.FilterEqOp,
Src: "m[\"zero\"].Value.Int() == 0",
Args: []ir.FilterExpr{
{
- Line: 301,
+ Line: 299,
Op: ir.FilterVarValueIntOp,
Src: "m[\"zero\"].Value.Int()",
Value: "zero",
},
{
- Line: 301,
+ Line: 299,
Op: ir.FilterIntOp,
Src: "0",
Value: int64(0),
@@ -985,22 +1002,22 @@ var PrecompiledRules = &ir.File{
LocationVar: "zero",
},
{
- Line: 303,
- SyntaxPatterns: []ir.PatternString{{Line: 303, Value: "bytes.SplitN($_, $_, $zero)"}},
+ Line: 301,
+ SyntaxPatterns: []ir.PatternString{{Line: 301, Value: "bytes.SplitN($_, $_, $zero)"}},
ReportTemplate: "suspicious arg 0, probably meant -1",
WhereExpr: ir.FilterExpr{
- Line: 304,
+ Line: 302,
Op: ir.FilterEqOp,
Src: "m[\"zero\"].Value.Int() == 0",
Args: []ir.FilterExpr{
{
- Line: 304,
+ Line: 302,
Op: ir.FilterVarValueIntOp,
Src: "m[\"zero\"].Value.Int()",
Value: "zero",
},
{
- Line: 304,
+ Line: 302,
Op: ir.FilterIntOp,
Src: "0",
Value: int64(0),
@@ -1010,19 +1027,19 @@ var PrecompiledRules = &ir.File{
LocationVar: "zero",
},
{
- Line: 307,
- SyntaxPatterns: []ir.PatternString{{Line: 307, Value: "append($_)"}},
+ Line: 305,
+ SyntaxPatterns: []ir.PatternString{{Line: 305, Value: "append($_)"}},
ReportTemplate: "no-op append call, probably missing arguments",
},
{
- Line: 309,
- SyntaxPatterns: []ir.PatternString{{Line: 309, Value: "filepath.Join($_)"}},
+ Line: 307,
+ SyntaxPatterns: []ir.PatternString{{Line: 307, Value: "filepath.Join($_)"}},
ReportTemplate: "suspicious Join on 1 argument",
},
},
},
{
- Line: 316,
+ Line: 314,
Name: "assignOp",
MatcherName: "m",
DocTags: []string{"style"},
@@ -1031,87 +1048,87 @@ var PrecompiledRules = &ir.File{
DocAfter: "x *= 2",
Rules: []ir.Rule{
{
- Line: 317,
- SyntaxPatterns: []ir.PatternString{{Line: 317, Value: "$x = $x + 1"}},
+ Line: 315,
+ SyntaxPatterns: []ir.PatternString{{Line: 315, Value: "$x = $x + 1"}},
ReportTemplate: "replace `$$` with `$x++`",
- WhereExpr: ir.FilterExpr{Line: 317, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 315, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 318,
- SyntaxPatterns: []ir.PatternString{{Line: 318, Value: "$x = $x - 1"}},
+ Line: 316,
+ SyntaxPatterns: []ir.PatternString{{Line: 316, Value: "$x = $x - 1"}},
ReportTemplate: "replace `$$` with `$x--`",
- WhereExpr: ir.FilterExpr{Line: 318, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 316, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 320,
- SyntaxPatterns: []ir.PatternString{{Line: 320, Value: "$x = $x + $y"}},
+ Line: 318,
+ SyntaxPatterns: []ir.PatternString{{Line: 318, Value: "$x = $x + $y"}},
ReportTemplate: "replace `$$` with `$x += $y`",
- WhereExpr: ir.FilterExpr{Line: 320, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 318, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 321,
- SyntaxPatterns: []ir.PatternString{{Line: 321, Value: "$x = $x - $y"}},
+ Line: 319,
+ SyntaxPatterns: []ir.PatternString{{Line: 319, Value: "$x = $x - $y"}},
ReportTemplate: "replace `$$` with `$x -= $y`",
+ WhereExpr: ir.FilterExpr{Line: 319, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ },
+ {
+ Line: 321,
+ SyntaxPatterns: []ir.PatternString{{Line: 321, Value: "$x = $x * $y"}},
+ ReportTemplate: "replace `$$` with `$x *= $y`",
WhereExpr: ir.FilterExpr{Line: 321, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
+ Line: 322,
+ SyntaxPatterns: []ir.PatternString{{Line: 322, Value: "$x = $x / $y"}},
+ ReportTemplate: "replace `$$` with `$x /= $y`",
+ WhereExpr: ir.FilterExpr{Line: 322, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ },
+ {
Line: 323,
- SyntaxPatterns: []ir.PatternString{{Line: 323, Value: "$x = $x * $y"}},
- ReportTemplate: "replace `$$` with `$x *= $y`",
+ SyntaxPatterns: []ir.PatternString{{Line: 323, Value: "$x = $x % $y"}},
+ ReportTemplate: "replace `$$` with `$x %= $y`",
WhereExpr: ir.FilterExpr{Line: 323, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
Line: 324,
- SyntaxPatterns: []ir.PatternString{{Line: 324, Value: "$x = $x / $y"}},
- ReportTemplate: "replace `$$` with `$x /= $y`",
+ SyntaxPatterns: []ir.PatternString{{Line: 324, Value: "$x = $x & $y"}},
+ ReportTemplate: "replace `$$` with `$x &= $y`",
WhereExpr: ir.FilterExpr{Line: 324, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
Line: 325,
- SyntaxPatterns: []ir.PatternString{{Line: 325, Value: "$x = $x % $y"}},
- ReportTemplate: "replace `$$` with `$x %= $y`",
+ SyntaxPatterns: []ir.PatternString{{Line: 325, Value: "$x = $x | $y"}},
+ ReportTemplate: "replace `$$` with `$x |= $y`",
WhereExpr: ir.FilterExpr{Line: 325, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
Line: 326,
- SyntaxPatterns: []ir.PatternString{{Line: 326, Value: "$x = $x & $y"}},
- ReportTemplate: "replace `$$` with `$x &= $y`",
+ SyntaxPatterns: []ir.PatternString{{Line: 326, Value: "$x = $x ^ $y"}},
+ ReportTemplate: "replace `$$` with `$x ^= $y`",
WhereExpr: ir.FilterExpr{Line: 326, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
Line: 327,
- SyntaxPatterns: []ir.PatternString{{Line: 327, Value: "$x = $x | $y"}},
- ReportTemplate: "replace `$$` with `$x |= $y`",
+ SyntaxPatterns: []ir.PatternString{{Line: 327, Value: "$x = $x << $y"}},
+ ReportTemplate: "replace `$$` with `$x <<= $y`",
WhereExpr: ir.FilterExpr{Line: 327, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
Line: 328,
- SyntaxPatterns: []ir.PatternString{{Line: 328, Value: "$x = $x ^ $y"}},
- ReportTemplate: "replace `$$` with `$x ^= $y`",
+ SyntaxPatterns: []ir.PatternString{{Line: 328, Value: "$x = $x >> $y"}},
+ ReportTemplate: "replace `$$` with `$x >>= $y`",
WhereExpr: ir.FilterExpr{Line: 328, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
Line: 329,
- SyntaxPatterns: []ir.PatternString{{Line: 329, Value: "$x = $x << $y"}},
- ReportTemplate: "replace `$$` with `$x <<= $y`",
- WhereExpr: ir.FilterExpr{Line: 329, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
- },
- {
- Line: 330,
- SyntaxPatterns: []ir.PatternString{{Line: 330, Value: "$x = $x >> $y"}},
- ReportTemplate: "replace `$$` with `$x >>= $y`",
- WhereExpr: ir.FilterExpr{Line: 330, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
- },
- {
- Line: 331,
- SyntaxPatterns: []ir.PatternString{{Line: 331, Value: "$x = $x &^ $y"}},
+ SyntaxPatterns: []ir.PatternString{{Line: 329, Value: "$x = $x &^ $y"}},
ReportTemplate: "replace `$$` with `$x &^= $y`",
- WhereExpr: ir.FilterExpr{Line: 331, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 329, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
},
},
{
- Line: 338,
+ Line: 336,
Name: "preferWriteByte",
MatcherName: "m",
DocTags: []string{"performance", "experimental", "opinionated"},
@@ -1119,45 +1136,45 @@ var PrecompiledRules = &ir.File{
DocBefore: "w.WriteRune('\\n')",
DocAfter: "w.WriteByte('\\n')",
Rules: []ir.Rule{{
- Line: 342,
- SyntaxPatterns: []ir.PatternString{{Line: 342, Value: "$w.WriteRune($c)"}},
+ Line: 340,
+ SyntaxPatterns: []ir.PatternString{{Line: 340, Value: "$w.WriteRune($c)"}},
ReportTemplate: "consider writing single byte rune $c with $w.WriteByte($c)",
WhereExpr: ir.FilterExpr{
- Line: 343,
+ Line: 341,
Op: ir.FilterAndOp,
Src: "m[\"w\"].Type.Implements(\"io.ByteWriter\") && (m[\"c\"].Const && m[\"c\"].Value.Int() < runeSelf)",
Args: []ir.FilterExpr{
{
- Line: 343,
+ Line: 341,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.ByteWriter\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 343, Op: ir.FilterStringOp, Src: "\"io.ByteWriter\"", Value: "io.ByteWriter"}},
+ Args: []ir.FilterExpr{{Line: 341, Op: ir.FilterStringOp, Src: "\"io.ByteWriter\"", Value: "io.ByteWriter"}},
},
{
- Line: 343,
+ Line: 341,
Op: ir.FilterAndOp,
Src: "(m[\"c\"].Const && m[\"c\"].Value.Int() < runeSelf)",
Args: []ir.FilterExpr{
{
- Line: 343,
+ Line: 341,
Op: ir.FilterVarConstOp,
Src: "m[\"c\"].Const",
Value: "c",
},
{
- Line: 343,
+ Line: 341,
Op: ir.FilterLtOp,
Src: "m[\"c\"].Value.Int() < runeSelf",
Args: []ir.FilterExpr{
{
- Line: 343,
+ Line: 341,
Op: ir.FilterVarValueIntOp,
Src: "m[\"c\"].Value.Int()",
Value: "c",
},
{
- Line: 343,
+ Line: 341,
Op: ir.FilterIntOp,
Src: "runeSelf",
Value: int64(128),
@@ -1171,7 +1188,7 @@ var PrecompiledRules = &ir.File{
}},
},
{
- Line: 351,
+ Line: 349,
Name: "preferFprint",
MatcherName: "m",
DocTags: []string{"performance", "experimental"},
@@ -1180,66 +1197,66 @@ var PrecompiledRules = &ir.File{
DocAfter: "fmt.Fprintf(w, \"%x\", 10)",
Rules: []ir.Rule{
{
- Line: 352,
- SyntaxPatterns: []ir.PatternString{{Line: 352, Value: "$w.Write([]byte(fmt.Sprint($*args)))"}},
+ Line: 350,
+ SyntaxPatterns: []ir.PatternString{{Line: 350, Value: "$w.Write([]byte(fmt.Sprint($*args)))"}},
ReportTemplate: "fmt.Fprint($w, $args) should be preferred to the $$",
SuggestTemplate: "fmt.Fprint($w, $args)",
WhereExpr: ir.FilterExpr{
- Line: 353,
+ Line: 351,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.Writer\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 353, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
+ Args: []ir.FilterExpr{{Line: 351, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
},
},
{
- Line: 357,
- SyntaxPatterns: []ir.PatternString{{Line: 357, Value: "$w.Write([]byte(fmt.Sprintf($*args)))"}},
+ Line: 355,
+ SyntaxPatterns: []ir.PatternString{{Line: 355, Value: "$w.Write([]byte(fmt.Sprintf($*args)))"}},
ReportTemplate: "fmt.Fprintf($w, $args) should be preferred to the $$",
SuggestTemplate: "fmt.Fprintf($w, $args)",
WhereExpr: ir.FilterExpr{
- Line: 358,
+ Line: 356,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.Writer\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 358, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
+ Args: []ir.FilterExpr{{Line: 356, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
},
},
{
- Line: 362,
- SyntaxPatterns: []ir.PatternString{{Line: 362, Value: "$w.Write([]byte(fmt.Sprintln($*args)))"}},
+ Line: 360,
+ SyntaxPatterns: []ir.PatternString{{Line: 360, Value: "$w.Write([]byte(fmt.Sprintln($*args)))"}},
ReportTemplate: "fmt.Fprintln($w, $args) should be preferred to the $$",
SuggestTemplate: "fmt.Fprintln($w, $args)",
WhereExpr: ir.FilterExpr{
- Line: 363,
+ Line: 361,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.Writer\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 363, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
+ Args: []ir.FilterExpr{{Line: 361, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
},
},
{
- Line: 367,
- SyntaxPatterns: []ir.PatternString{{Line: 367, Value: "io.WriteString($w, fmt.Sprint($*args))"}},
+ Line: 365,
+ SyntaxPatterns: []ir.PatternString{{Line: 365, Value: "io.WriteString($w, fmt.Sprint($*args))"}},
ReportTemplate: "suggestion: fmt.Fprint($w, $args)",
SuggestTemplate: "fmt.Fprint($w, $args)",
},
{
- Line: 368,
- SyntaxPatterns: []ir.PatternString{{Line: 368, Value: "io.WriteString($w, fmt.Sprintf($*args))"}},
+ Line: 366,
+ SyntaxPatterns: []ir.PatternString{{Line: 366, Value: "io.WriteString($w, fmt.Sprintf($*args))"}},
ReportTemplate: "suggestion: fmt.Fprintf($w, $args)",
SuggestTemplate: "fmt.Fprintf($w, $args)",
},
{
- Line: 369,
- SyntaxPatterns: []ir.PatternString{{Line: 369, Value: "io.WriteString($w, fmt.Sprintln($*args))"}},
+ Line: 367,
+ SyntaxPatterns: []ir.PatternString{{Line: 367, Value: "io.WriteString($w, fmt.Sprintln($*args))"}},
ReportTemplate: "suggestion: fmt.Fprintln($w, $args)",
SuggestTemplate: "fmt.Fprintln($w, $args)",
},
},
},
{
- Line: 376,
+ Line: 374,
Name: "dupArg",
MatcherName: "m",
DocTags: []string{"diagnostic"},
@@ -1248,62 +1265,62 @@ var PrecompiledRules = &ir.File{
DocAfter: "copy(dst, src)",
Rules: []ir.Rule{
{
- Line: 377,
+ Line: 375,
SyntaxPatterns: []ir.PatternString{
- {Line: 377, Value: "$x.Equal($x)"},
- {Line: 377, Value: "$x.Equals($x)"},
- {Line: 377, Value: "$x.Compare($x)"},
- {Line: 377, Value: "$x.Cmp($x)"},
+ {Line: 375, Value: "$x.Equal($x)"},
+ {Line: 375, Value: "$x.Equals($x)"},
+ {Line: 375, Value: "$x.Compare($x)"},
+ {Line: 375, Value: "$x.Cmp($x)"},
},
ReportTemplate: "suspicious method call with the same argument and receiver",
- WhereExpr: ir.FilterExpr{Line: 378, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 376, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 381,
+ Line: 379,
SyntaxPatterns: []ir.PatternString{
- {Line: 381, Value: "copy($x, $x)"},
- {Line: 382, Value: "math.Max($x, $x)"},
- {Line: 383, Value: "math.Min($x, $x)"},
- {Line: 384, Value: "reflect.Copy($x, $x)"},
- {Line: 385, Value: "reflect.DeepEqual($x, $x)"},
- {Line: 386, Value: "strings.Contains($x, $x)"},
- {Line: 387, Value: "strings.Compare($x, $x)"},
- {Line: 388, Value: "strings.EqualFold($x, $x)"},
- {Line: 389, Value: "strings.HasPrefix($x, $x)"},
- {Line: 390, Value: "strings.HasSuffix($x, $x)"},
- {Line: 391, Value: "strings.Index($x, $x)"},
- {Line: 392, Value: "strings.LastIndex($x, $x)"},
- {Line: 393, Value: "strings.Split($x, $x)"},
- {Line: 394, Value: "strings.SplitAfter($x, $x)"},
- {Line: 395, Value: "strings.SplitAfterN($x, $x, $_)"},
- {Line: 396, Value: "strings.SplitN($x, $x, $_)"},
- {Line: 397, Value: "strings.Replace($_, $x, $x, $_)"},
- {Line: 398, Value: "strings.ReplaceAll($_, $x, $x)"},
- {Line: 399, Value: "bytes.Contains($x, $x)"},
- {Line: 400, Value: "bytes.Compare($x, $x)"},
- {Line: 401, Value: "bytes.Equal($x, $x)"},
- {Line: 402, Value: "bytes.EqualFold($x, $x)"},
- {Line: 403, Value: "bytes.HasPrefix($x, $x)"},
- {Line: 404, Value: "bytes.HasSuffix($x, $x)"},
- {Line: 405, Value: "bytes.Index($x, $x)"},
- {Line: 406, Value: "bytes.LastIndex($x, $x)"},
- {Line: 407, Value: "bytes.Split($x, $x)"},
- {Line: 408, Value: "bytes.SplitAfter($x, $x)"},
- {Line: 409, Value: "bytes.SplitAfterN($x, $x, $_)"},
- {Line: 410, Value: "bytes.SplitN($x, $x, $_)"},
- {Line: 411, Value: "bytes.Replace($_, $x, $x, $_)"},
- {Line: 412, Value: "bytes.ReplaceAll($_, $x, $x)"},
- {Line: 413, Value: "types.Identical($x, $x)"},
- {Line: 414, Value: "types.IdenticalIgnoreTags($x, $x)"},
- {Line: 415, Value: "draw.Draw($x, $_, $x, $_, $_)"},
+ {Line: 379, Value: "copy($x, $x)"},
+ {Line: 380, Value: "math.Max($x, $x)"},
+ {Line: 381, Value: "math.Min($x, $x)"},
+ {Line: 382, Value: "reflect.Copy($x, $x)"},
+ {Line: 383, Value: "reflect.DeepEqual($x, $x)"},
+ {Line: 384, Value: "strings.Contains($x, $x)"},
+ {Line: 385, Value: "strings.Compare($x, $x)"},
+ {Line: 386, Value: "strings.EqualFold($x, $x)"},
+ {Line: 387, Value: "strings.HasPrefix($x, $x)"},
+ {Line: 388, Value: "strings.HasSuffix($x, $x)"},
+ {Line: 389, Value: "strings.Index($x, $x)"},
+ {Line: 390, Value: "strings.LastIndex($x, $x)"},
+ {Line: 391, Value: "strings.Split($x, $x)"},
+ {Line: 392, Value: "strings.SplitAfter($x, $x)"},
+ {Line: 393, Value: "strings.SplitAfterN($x, $x, $_)"},
+ {Line: 394, Value: "strings.SplitN($x, $x, $_)"},
+ {Line: 395, Value: "strings.Replace($_, $x, $x, $_)"},
+ {Line: 396, Value: "strings.ReplaceAll($_, $x, $x)"},
+ {Line: 397, Value: "bytes.Contains($x, $x)"},
+ {Line: 398, Value: "bytes.Compare($x, $x)"},
+ {Line: 399, Value: "bytes.Equal($x, $x)"},
+ {Line: 400, Value: "bytes.EqualFold($x, $x)"},
+ {Line: 401, Value: "bytes.HasPrefix($x, $x)"},
+ {Line: 402, Value: "bytes.HasSuffix($x, $x)"},
+ {Line: 403, Value: "bytes.Index($x, $x)"},
+ {Line: 404, Value: "bytes.LastIndex($x, $x)"},
+ {Line: 405, Value: "bytes.Split($x, $x)"},
+ {Line: 406, Value: "bytes.SplitAfter($x, $x)"},
+ {Line: 407, Value: "bytes.SplitAfterN($x, $x, $_)"},
+ {Line: 408, Value: "bytes.SplitN($x, $x, $_)"},
+ {Line: 409, Value: "bytes.Replace($_, $x, $x, $_)"},
+ {Line: 410, Value: "bytes.ReplaceAll($_, $x, $x)"},
+ {Line: 411, Value: "types.Identical($x, $x)"},
+ {Line: 412, Value: "types.IdenticalIgnoreTags($x, $x)"},
+ {Line: 413, Value: "draw.Draw($x, $_, $x, $_, $_)"},
},
ReportTemplate: "suspicious duplicated args in $$",
- WhereExpr: ir.FilterExpr{Line: 416, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 414, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
},
},
{
- Line: 424,
+ Line: 422,
Name: "returnAfterHttpError",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -1311,14 +1328,14 @@ var PrecompiledRules = &ir.File{
DocBefore: "if err != nil { http.Error(...); }",
DocAfter: "if err != nil { http.Error(...); return; }",
Rules: []ir.Rule{{
- Line: 425,
- SyntaxPatterns: []ir.PatternString{{Line: 425, Value: "if $_ { $*_; http.Error($w, $err, $code) }"}},
+ Line: 423,
+ SyntaxPatterns: []ir.PatternString{{Line: 423, Value: "if $_ { $*_; http.Error($w, $err, $code) }"}},
ReportTemplate: "Possibly return is missed after the http.Error call",
LocationVar: "w",
}},
},
{
- Line: 434,
+ Line: 432,
Name: "preferFilepathJoin",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -1326,35 +1343,35 @@ var PrecompiledRules = &ir.File{
DocBefore: "x + string(os.PathSeparator) + y",
DocAfter: "filepath.Join(x, y)",
Rules: []ir.Rule{{
- Line: 435,
- SyntaxPatterns: []ir.PatternString{{Line: 435, Value: "$x + string(os.PathSeparator) + $y"}},
+ Line: 433,
+ SyntaxPatterns: []ir.PatternString{{Line: 433, Value: "$x + string(os.PathSeparator) + $y"}},
ReportTemplate: "filepath.Join($x, $y) should be preferred to the $$",
SuggestTemplate: "filepath.Join($x, $y)",
WhereExpr: ir.FilterExpr{
- Line: 436,
+ Line: 434,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Type.Is(`string`) && m[\"y\"].Type.Is(`string`)",
Args: []ir.FilterExpr{
{
- Line: 436,
+ Line: 434,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`string`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 436, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 434, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
{
- Line: 436,
+ Line: 434,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"y\"].Type.Is(`string`)",
Value: "y",
- Args: []ir.FilterExpr{{Line: 436, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 434, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
},
},
}},
},
{
- Line: 445,
+ Line: 443,
Name: "preferStringWriter",
MatcherName: "m",
DocTags: []string{"performance", "experimental"},
@@ -1363,35 +1380,35 @@ var PrecompiledRules = &ir.File{
DocAfter: "w.WriteString(\"foo\")",
Rules: []ir.Rule{
{
- Line: 446,
- SyntaxPatterns: []ir.PatternString{{Line: 446, Value: "$w.Write([]byte($s))"}},
+ Line: 444,
+ SyntaxPatterns: []ir.PatternString{{Line: 444, Value: "$w.Write([]byte($s))"}},
ReportTemplate: "$w.WriteString($s) should be preferred to the $$",
SuggestTemplate: "$w.WriteString($s)",
WhereExpr: ir.FilterExpr{
- Line: 447,
+ Line: 445,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.StringWriter\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 447, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
+ Args: []ir.FilterExpr{{Line: 445, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
},
},
{
- Line: 451,
- SyntaxPatterns: []ir.PatternString{{Line: 451, Value: "io.WriteString($w, $s)"}},
+ Line: 449,
+ SyntaxPatterns: []ir.PatternString{{Line: 449, Value: "io.WriteString($w, $s)"}},
ReportTemplate: "$w.WriteString($s) should be preferred to the $$",
SuggestTemplate: "$w.WriteString($s)",
WhereExpr: ir.FilterExpr{
- Line: 452,
+ Line: 450,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.StringWriter\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 452, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
+ Args: []ir.FilterExpr{{Line: 450, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
},
},
},
},
{
- Line: 461,
+ Line: 459,
Name: "sliceClear",
MatcherName: "m",
DocTags: []string{"performance", "experimental"},
@@ -1399,22 +1416,22 @@ var PrecompiledRules = &ir.File{
DocBefore: "for i := 0; i < len(buf); i++ { buf[i] = 0 }",
DocAfter: "for i := range buf { buf[i] = 0 }",
Rules: []ir.Rule{{
- Line: 462,
- SyntaxPatterns: []ir.PatternString{{Line: 462, Value: "for $i := 0; $i < len($xs); $i++ { $xs[$i] = $zero }"}},
+ Line: 460,
+ SyntaxPatterns: []ir.PatternString{{Line: 460, Value: "for $i := 0; $i < len($xs); $i++ { $xs[$i] = $zero }"}},
ReportTemplate: "rewrite as for-range so compiler can recognize this pattern",
WhereExpr: ir.FilterExpr{
- Line: 463,
+ Line: 461,
Op: ir.FilterEqOp,
Src: "m[\"zero\"].Value.Int() == 0",
Args: []ir.FilterExpr{
{
- Line: 463,
+ Line: 461,
Op: ir.FilterVarValueIntOp,
Src: "m[\"zero\"].Value.Int()",
Value: "zero",
},
{
- Line: 463,
+ Line: 461,
Op: ir.FilterIntOp,
Src: "0",
Value: int64(0),
@@ -1424,7 +1441,7 @@ var PrecompiledRules = &ir.File{
}},
},
{
- Line: 471,
+ Line: 469,
Name: "syncMapLoadAndDelete",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -1432,33 +1449,33 @@ var PrecompiledRules = &ir.File{
DocBefore: "v, ok := m.Load(k); if ok { m.Delete($k); f(v); }",
DocAfter: "v, deleted := m.LoadAndDelete(k); if deleted { f(v) }",
Rules: []ir.Rule{{
- Line: 472,
- SyntaxPatterns: []ir.PatternString{{Line: 472, Value: "$_, $ok := $m.Load($k); if $ok { $m.Delete($k); $*_ }"}},
+ Line: 470,
+ SyntaxPatterns: []ir.PatternString{{Line: 470, Value: "$_, $ok := $m.Load($k); if $ok { $m.Delete($k); $*_ }"}},
ReportTemplate: "use $m.LoadAndDelete to perform load+delete operations atomically",
WhereExpr: ir.FilterExpr{
- Line: 473,
+ Line: 471,
Op: ir.FilterAndOp,
Src: "m.GoVersion().GreaterEqThan(\"1.15\") &&\n\tm[\"m\"].Type.Is(`*sync.Map`)",
Args: []ir.FilterExpr{
{
- Line: 473,
+ Line: 471,
Op: ir.FilterGoVersionGreaterEqThanOp,
Src: "m.GoVersion().GreaterEqThan(\"1.15\")",
Value: "1.15",
},
{
- Line: 474,
+ Line: 472,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"m\"].Type.Is(`*sync.Map`)",
Value: "m",
- Args: []ir.FilterExpr{{Line: 474, Op: ir.FilterStringOp, Src: "`*sync.Map`", Value: "*sync.Map"}},
+ Args: []ir.FilterExpr{{Line: 472, Op: ir.FilterStringOp, Src: "`*sync.Map`", Value: "*sync.Map"}},
},
},
},
}},
},
{
- Line: 482,
+ Line: 480,
Name: "sprintfQuotedString",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -1466,34 +1483,34 @@ var PrecompiledRules = &ir.File{
DocBefore: "fmt.Sprintf(`\"%s\"`, s)",
DocAfter: "fmt.Sprintf(`%q`, s)",
Rules: []ir.Rule{{
- Line: 483,
- SyntaxPatterns: []ir.PatternString{{Line: 483, Value: "fmt.Sprintf($s, $*_)"}},
+ Line: 481,
+ SyntaxPatterns: []ir.PatternString{{Line: 481, Value: "fmt.Sprintf($s, $*_)"}},
ReportTemplate: "use %q instead of \"%s\" for quoted strings",
WhereExpr: ir.FilterExpr{
- Line: 484,
+ Line: 482,
Op: ir.FilterOrOp,
Src: "m[\"s\"].Text.Matches(\"^`.*\\\"%s\\\".*`$\") ||\n\tm[\"s\"].Text.Matches(`^\".*\\\\\"%s\\\\\".*\"$`)",
Args: []ir.FilterExpr{
{
- Line: 484,
+ Line: 482,
Op: ir.FilterVarTextMatchesOp,
Src: "m[\"s\"].Text.Matches(\"^`.*\\\"%s\\\".*`$\")",
Value: "s",
- Args: []ir.FilterExpr{{Line: 484, Op: ir.FilterStringOp, Src: "\"^`.*\\\"%s\\\".*`$\"", Value: "^`.*\"%s\".*`$"}},
+ Args: []ir.FilterExpr{{Line: 482, Op: ir.FilterStringOp, Src: "\"^`.*\\\"%s\\\".*`$\"", Value: "^`.*\"%s\".*`$"}},
},
{
- Line: 485,
+ Line: 483,
Op: ir.FilterVarTextMatchesOp,
Src: "m[\"s\"].Text.Matches(`^\".*\\\\\"%s\\\\\".*\"$`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 485, Op: ir.FilterStringOp, Src: "`^\".*\\\\\"%s\\\\\".*\"$`", Value: "^\".*\\\\\"%s\\\\\".*\"$"}},
+ Args: []ir.FilterExpr{{Line: 483, Op: ir.FilterStringOp, Src: "`^\".*\\\\\"%s\\\\\".*\"$`", Value: "^\".*\\\\\"%s\\\\\".*\"$"}},
},
},
},
}},
},
{
- Line: 493,
+ Line: 491,
Name: "offBy1",
MatcherName: "m",
DocTags: []string{"diagnostic"},
@@ -1502,80 +1519,80 @@ var PrecompiledRules = &ir.File{
DocAfter: "xs[len(xs)-1]",
Rules: []ir.Rule{
{
- Line: 494,
- SyntaxPatterns: []ir.PatternString{{Line: 494, Value: "$x[len($x)]"}},
+ Line: 492,
+ SyntaxPatterns: []ir.PatternString{{Line: 492, Value: "$x[len($x)]"}},
ReportTemplate: "index expr always panics; maybe you wanted $x[len($x)-1]?",
SuggestTemplate: "$x[len($x)-1]",
WhereExpr: ir.FilterExpr{
- Line: 495,
+ Line: 493,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"x\"].Type.Is(`[]$_`)",
Args: []ir.FilterExpr{
- {Line: 495, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ {Line: 493, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
{
- Line: 495,
+ Line: 493,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`[]$_`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 495, Op: ir.FilterStringOp, Src: "`[]$_`", Value: "[]$_"}},
+ Args: []ir.FilterExpr{{Line: 493, Op: ir.FilterStringOp, Src: "`[]$_`", Value: "[]$_"}},
},
},
},
},
{
- Line: 502,
+ Line: 500,
SyntaxPatterns: []ir.PatternString{
- {Line: 503, Value: "$i := strings.Index($s, $_); $_ := $slicing[$i:]"},
- {Line: 504, Value: "$i := strings.Index($s, $_); $_ = $slicing[$i:]"},
- {Line: 505, Value: "$i := bytes.Index($s, $_); $_ := $slicing[$i:]"},
- {Line: 506, Value: "$i := bytes.Index($s, $_); $_ = $slicing[$i:]"},
+ {Line: 501, Value: "$i := strings.Index($s, $_); $_ := $slicing[$i:]"},
+ {Line: 502, Value: "$i := strings.Index($s, $_); $_ = $slicing[$i:]"},
+ {Line: 503, Value: "$i := bytes.Index($s, $_); $_ := $slicing[$i:]"},
+ {Line: 504, Value: "$i := bytes.Index($s, $_); $_ = $slicing[$i:]"},
},
ReportTemplate: "Index() can return -1; maybe you wanted to do $s[$i+1:]",
WhereExpr: ir.FilterExpr{
- Line: 507,
+ Line: 505,
Op: ir.FilterEqOp,
Src: "m[\"s\"].Text == m[\"slicing\"].Text",
Args: []ir.FilterExpr{
- {Line: 507, Op: ir.FilterVarTextOp, Src: "m[\"s\"].Text", Value: "s"},
- {Line: 507, Op: ir.FilterVarTextOp, Src: "m[\"slicing\"].Text", Value: "slicing"},
+ {Line: 505, Op: ir.FilterVarTextOp, Src: "m[\"s\"].Text", Value: "s"},
+ {Line: 505, Op: ir.FilterVarTextOp, Src: "m[\"slicing\"].Text", Value: "slicing"},
},
},
LocationVar: "slicing",
},
{
- Line: 511,
+ Line: 509,
SyntaxPatterns: []ir.PatternString{
- {Line: 512, Value: "$i := strings.Index($s, $_); $_ := $slicing[:$i]"},
- {Line: 513, Value: "$i := strings.Index($s, $_); $_ = $slicing[:$i]"},
- {Line: 514, Value: "$i := bytes.Index($s, $_); $_ := $slicing[:$i]"},
- {Line: 515, Value: "$i := bytes.Index($s, $_); $_ = $slicing[:$i]"},
+ {Line: 510, Value: "$i := strings.Index($s, $_); $_ := $slicing[:$i]"},
+ {Line: 511, Value: "$i := strings.Index($s, $_); $_ = $slicing[:$i]"},
+ {Line: 512, Value: "$i := bytes.Index($s, $_); $_ := $slicing[:$i]"},
+ {Line: 513, Value: "$i := bytes.Index($s, $_); $_ = $slicing[:$i]"},
},
ReportTemplate: "Index() can return -1; maybe you wanted to do $s[:$i+1]",
WhereExpr: ir.FilterExpr{
- Line: 516,
+ Line: 514,
Op: ir.FilterEqOp,
Src: "m[\"s\"].Text == m[\"slicing\"].Text",
Args: []ir.FilterExpr{
- {Line: 516, Op: ir.FilterVarTextOp, Src: "m[\"s\"].Text", Value: "s"},
- {Line: 516, Op: ir.FilterVarTextOp, Src: "m[\"slicing\"].Text", Value: "slicing"},
+ {Line: 514, Op: ir.FilterVarTextOp, Src: "m[\"s\"].Text", Value: "s"},
+ {Line: 514, Op: ir.FilterVarTextOp, Src: "m[\"slicing\"].Text", Value: "slicing"},
},
},
LocationVar: "slicing",
},
{
- Line: 520,
+ Line: 518,
SyntaxPatterns: []ir.PatternString{
- {Line: 521, Value: "$s[strings.Index($s, $_):]"},
- {Line: 522, Value: "$s[:strings.Index($s, $_)]"},
- {Line: 523, Value: "$s[bytes.Index($s, $_):]"},
- {Line: 524, Value: "$s[:bytes.Index($s, $_)]"},
+ {Line: 519, Value: "$s[strings.Index($s, $_):]"},
+ {Line: 520, Value: "$s[:strings.Index($s, $_)]"},
+ {Line: 521, Value: "$s[bytes.Index($s, $_):]"},
+ {Line: 522, Value: "$s[:bytes.Index($s, $_)]"},
},
ReportTemplate: "Index() can return -1; maybe you wanted to do Index()+1",
},
},
},
{
- Line: 532,
+ Line: 530,
Name: "unslice",
MatcherName: "m",
DocTags: []string{"style"},
@@ -1583,35 +1600,35 @@ var PrecompiledRules = &ir.File{
DocBefore: "copy(b[:], values...)",
DocAfter: "copy(b, values...)",
Rules: []ir.Rule{{
- Line: 533,
- SyntaxPatterns: []ir.PatternString{{Line: 533, Value: "$s[:]"}},
+ Line: 531,
+ SyntaxPatterns: []ir.PatternString{{Line: 531, Value: "$s[:]"}},
ReportTemplate: "could simplify $$ to $s",
SuggestTemplate: "$s",
WhereExpr: ir.FilterExpr{
- Line: 534,
+ Line: 532,
Op: ir.FilterOrOp,
Src: "m[\"s\"].Type.Is(`string`) || m[\"s\"].Type.Is(`[]$_`)",
Args: []ir.FilterExpr{
{
- Line: 534,
+ Line: 532,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`string`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 534, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 532, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
{
- Line: 534,
+ Line: 532,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`[]$_`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 534, Op: ir.FilterStringOp, Src: "`[]$_`", Value: "[]$_"}},
+ Args: []ir.FilterExpr{{Line: 532, Op: ir.FilterStringOp, Src: "`[]$_`", Value: "[]$_"}},
},
},
},
}},
},
{
- Line: 543,
+ Line: 541,
Name: "yodaStyleExpr",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -1620,105 +1637,105 @@ var PrecompiledRules = &ir.File{
DocAfter: "return ptr != nil",
Rules: []ir.Rule{
{
- Line: 544,
- SyntaxPatterns: []ir.PatternString{{Line: 544, Value: "$constval != $x"}},
+ Line: 542,
+ SyntaxPatterns: []ir.PatternString{{Line: 542, Value: "$constval != $x"}},
ReportTemplate: "consider to change order in expression to $x != $constval",
WhereExpr: ir.FilterExpr{
- Line: 544,
+ Line: 542,
Op: ir.FilterAndOp,
Src: "m[\"constval\"].Node.Is(`BasicLit`) && !m[\"x\"].Node.Is(`BasicLit`)",
Args: []ir.FilterExpr{
{
- Line: 544,
+ Line: 542,
Op: ir.FilterVarNodeIsOp,
Src: "m[\"constval\"].Node.Is(`BasicLit`)",
Value: "constval",
- Args: []ir.FilterExpr{{Line: 544, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
+ Args: []ir.FilterExpr{{Line: 542, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
},
{
- Line: 544,
+ Line: 542,
Op: ir.FilterNotOp,
Src: "!m[\"x\"].Node.Is(`BasicLit`)",
Args: []ir.FilterExpr{{
- Line: 544,
+ Line: 542,
Op: ir.FilterVarNodeIsOp,
Src: "m[\"x\"].Node.Is(`BasicLit`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 544, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
+ Args: []ir.FilterExpr{{Line: 542, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
}},
},
},
},
},
{
- Line: 546,
- SyntaxPatterns: []ir.PatternString{{Line: 546, Value: "$constval == $x"}},
+ Line: 544,
+ SyntaxPatterns: []ir.PatternString{{Line: 544, Value: "$constval == $x"}},
ReportTemplate: "consider to change order in expression to $x == $constval",
WhereExpr: ir.FilterExpr{
- Line: 546,
+ Line: 544,
Op: ir.FilterAndOp,
Src: "m[\"constval\"].Node.Is(`BasicLit`) && !m[\"x\"].Node.Is(`BasicLit`)",
Args: []ir.FilterExpr{
{
- Line: 546,
+ Line: 544,
Op: ir.FilterVarNodeIsOp,
Src: "m[\"constval\"].Node.Is(`BasicLit`)",
Value: "constval",
- Args: []ir.FilterExpr{{Line: 546, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
+ Args: []ir.FilterExpr{{Line: 544, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
},
{
- Line: 546,
+ Line: 544,
Op: ir.FilterNotOp,
Src: "!m[\"x\"].Node.Is(`BasicLit`)",
Args: []ir.FilterExpr{{
- Line: 546,
+ Line: 544,
Op: ir.FilterVarNodeIsOp,
Src: "m[\"x\"].Node.Is(`BasicLit`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 546, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
+ Args: []ir.FilterExpr{{Line: 544, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
}},
},
},
},
},
{
- Line: 549,
- SyntaxPatterns: []ir.PatternString{{Line: 549, Value: "nil != $x"}},
+ Line: 547,
+ SyntaxPatterns: []ir.PatternString{{Line: 547, Value: "nil != $x"}},
ReportTemplate: "consider to change order in expression to $x != nil",
WhereExpr: ir.FilterExpr{
- Line: 549,
+ Line: 547,
Op: ir.FilterNotOp,
Src: "!m[\"x\"].Node.Is(`BasicLit`)",
Args: []ir.FilterExpr{{
- Line: 549,
+ Line: 547,
Op: ir.FilterVarNodeIsOp,
Src: "m[\"x\"].Node.Is(`BasicLit`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 549, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
+ Args: []ir.FilterExpr{{Line: 547, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
}},
},
},
{
- Line: 551,
- SyntaxPatterns: []ir.PatternString{{Line: 551, Value: "nil == $x"}},
+ Line: 549,
+ SyntaxPatterns: []ir.PatternString{{Line: 549, Value: "nil == $x"}},
ReportTemplate: "consider to change order in expression to $x == nil",
WhereExpr: ir.FilterExpr{
- Line: 551,
+ Line: 549,
Op: ir.FilterNotOp,
Src: "!m[\"x\"].Node.Is(`BasicLit`)",
Args: []ir.FilterExpr{{
- Line: 551,
+ Line: 549,
Op: ir.FilterVarNodeIsOp,
Src: "m[\"x\"].Node.Is(`BasicLit`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 551, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
+ Args: []ir.FilterExpr{{Line: 549, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
}},
},
},
},
},
{
- Line: 559,
+ Line: 557,
Name: "equalFold",
MatcherName: "m",
DocTags: []string{"performance", "experimental"},
@@ -1727,114 +1744,114 @@ var PrecompiledRules = &ir.File{
DocAfter: "strings.EqualFold(x, y)",
Rules: []ir.Rule{
{
- Line: 568,
+ Line: 566,
SyntaxPatterns: []ir.PatternString{
- {Line: 569, Value: "strings.ToLower($x) == $y"},
- {Line: 570, Value: "strings.ToLower($x) == strings.ToLower($y)"},
- {Line: 571, Value: "$x == strings.ToLower($y)"},
- {Line: 572, Value: "strings.ToUpper($x) == $y"},
- {Line: 573, Value: "strings.ToUpper($x) == strings.ToUpper($y)"},
- {Line: 574, Value: "$x == strings.ToUpper($y)"},
+ {Line: 567, Value: "strings.ToLower($x) == $y"},
+ {Line: 568, Value: "strings.ToLower($x) == strings.ToLower($y)"},
+ {Line: 569, Value: "$x == strings.ToLower($y)"},
+ {Line: 570, Value: "strings.ToUpper($x) == $y"},
+ {Line: 571, Value: "strings.ToUpper($x) == strings.ToUpper($y)"},
+ {Line: 572, Value: "$x == strings.ToUpper($y)"},
},
ReportTemplate: "consider replacing with strings.EqualFold($x, $y)",
SuggestTemplate: "strings.EqualFold($x, $y)",
WhereExpr: ir.FilterExpr{
- Line: 575,
+ Line: 573,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure && m[\"x\"].Text != m[\"y\"].Text",
Args: []ir.FilterExpr{
{
- Line: 575,
+ Line: 573,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure",
Args: []ir.FilterExpr{
- {Line: 575, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
- {Line: 575, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
+ {Line: 573, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ {Line: 573, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
},
},
{
- Line: 575,
+ Line: 573,
Op: ir.FilterNeqOp,
Src: "m[\"x\"].Text != m[\"y\"].Text",
Args: []ir.FilterExpr{
- {Line: 575, Op: ir.FilterVarTextOp, Src: "m[\"x\"].Text", Value: "x"},
- {Line: 575, Op: ir.FilterVarTextOp, Src: "m[\"y\"].Text", Value: "y"},
+ {Line: 573, Op: ir.FilterVarTextOp, Src: "m[\"x\"].Text", Value: "x"},
+ {Line: 573, Op: ir.FilterVarTextOp, Src: "m[\"y\"].Text", Value: "y"},
},
},
},
},
},
{
- Line: 580,
+ Line: 578,
SyntaxPatterns: []ir.PatternString{
- {Line: 581, Value: "strings.ToLower($x) != $y"},
- {Line: 582, Value: "strings.ToLower($x) != strings.ToLower($y)"},
- {Line: 583, Value: "$x != strings.ToLower($y)"},
- {Line: 584, Value: "strings.ToUpper($x) != $y"},
- {Line: 585, Value: "strings.ToUpper($x) != strings.ToUpper($y)"},
- {Line: 586, Value: "$x != strings.ToUpper($y)"},
+ {Line: 579, Value: "strings.ToLower($x) != $y"},
+ {Line: 580, Value: "strings.ToLower($x) != strings.ToLower($y)"},
+ {Line: 581, Value: "$x != strings.ToLower($y)"},
+ {Line: 582, Value: "strings.ToUpper($x) != $y"},
+ {Line: 583, Value: "strings.ToUpper($x) != strings.ToUpper($y)"},
+ {Line: 584, Value: "$x != strings.ToUpper($y)"},
},
ReportTemplate: "consider replacing with !strings.EqualFold($x, $y)",
SuggestTemplate: "!strings.EqualFold($x, $y)",
WhereExpr: ir.FilterExpr{
- Line: 587,
+ Line: 585,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure && m[\"x\"].Text != m[\"y\"].Text",
Args: []ir.FilterExpr{
{
- Line: 587,
+ Line: 585,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure",
Args: []ir.FilterExpr{
- {Line: 587, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
- {Line: 587, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
+ {Line: 585, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ {Line: 585, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
},
},
{
- Line: 587,
+ Line: 585,
Op: ir.FilterNeqOp,
Src: "m[\"x\"].Text != m[\"y\"].Text",
Args: []ir.FilterExpr{
- {Line: 587, Op: ir.FilterVarTextOp, Src: "m[\"x\"].Text", Value: "x"},
- {Line: 587, Op: ir.FilterVarTextOp, Src: "m[\"y\"].Text", Value: "y"},
+ {Line: 585, Op: ir.FilterVarTextOp, Src: "m[\"x\"].Text", Value: "x"},
+ {Line: 585, Op: ir.FilterVarTextOp, Src: "m[\"y\"].Text", Value: "y"},
},
},
},
},
},
{
- Line: 592,
+ Line: 590,
SyntaxPatterns: []ir.PatternString{
- {Line: 593, Value: "bytes.Equal(bytes.ToLower($x), $y)"},
- {Line: 594, Value: "bytes.Equal(bytes.ToLower($x), bytes.ToLower($y))"},
- {Line: 595, Value: "bytes.Equal($x, bytes.ToLower($y))"},
- {Line: 596, Value: "bytes.Equal(bytes.ToUpper($x), $y)"},
- {Line: 597, Value: "bytes.Equal(bytes.ToUpper($x), bytes.ToUpper($y))"},
- {Line: 598, Value: "bytes.Equal($x, bytes.ToUpper($y))"},
+ {Line: 591, Value: "bytes.Equal(bytes.ToLower($x), $y)"},
+ {Line: 592, Value: "bytes.Equal(bytes.ToLower($x), bytes.ToLower($y))"},
+ {Line: 593, Value: "bytes.Equal($x, bytes.ToLower($y))"},
+ {Line: 594, Value: "bytes.Equal(bytes.ToUpper($x), $y)"},
+ {Line: 595, Value: "bytes.Equal(bytes.ToUpper($x), bytes.ToUpper($y))"},
+ {Line: 596, Value: "bytes.Equal($x, bytes.ToUpper($y))"},
},
ReportTemplate: "consider replacing with bytes.EqualFold($x, $y)",
SuggestTemplate: "bytes.EqualFold($x, $y)",
WhereExpr: ir.FilterExpr{
- Line: 599,
+ Line: 597,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure && m[\"x\"].Text != m[\"y\"].Text",
Args: []ir.FilterExpr{
{
- Line: 599,
+ Line: 597,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure",
Args: []ir.FilterExpr{
- {Line: 599, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
- {Line: 599, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
+ {Line: 597, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ {Line: 597, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
},
},
{
- Line: 599,
+ Line: 597,
Op: ir.FilterNeqOp,
Src: "m[\"x\"].Text != m[\"y\"].Text",
Args: []ir.FilterExpr{
- {Line: 599, Op: ir.FilterVarTextOp, Src: "m[\"x\"].Text", Value: "x"},
- {Line: 599, Op: ir.FilterVarTextOp, Src: "m[\"y\"].Text", Value: "y"},
+ {Line: 597, Op: ir.FilterVarTextOp, Src: "m[\"x\"].Text", Value: "x"},
+ {Line: 597, Op: ir.FilterVarTextOp, Src: "m[\"y\"].Text", Value: "y"},
},
},
},
@@ -1843,7 +1860,7 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 608,
+ Line: 606,
Name: "argOrder",
MatcherName: "m",
DocTags: []string{"diagnostic"},
@@ -1851,45 +1868,45 @@ var PrecompiledRules = &ir.File{
DocBefore: "strings.HasPrefix(\"#\", userpass)",
DocAfter: "strings.HasPrefix(userpass, \"#\")",
Rules: []ir.Rule{{
- Line: 609,
+ Line: 607,
SyntaxPatterns: []ir.PatternString{
- {Line: 610, Value: "strings.HasPrefix($lit, $s)"},
- {Line: 611, Value: "bytes.HasPrefix($lit, $s)"},
- {Line: 612, Value: "strings.HasSuffix($lit, $s)"},
- {Line: 613, Value: "bytes.HasSuffix($lit, $s)"},
- {Line: 614, Value: "strings.Contains($lit, $s)"},
- {Line: 615, Value: "bytes.Contains($lit, $s)"},
- {Line: 616, Value: "strings.TrimPrefix($lit, $s)"},
- {Line: 617, Value: "bytes.TrimPrefix($lit, $s)"},
- {Line: 618, Value: "strings.TrimSuffix($lit, $s)"},
- {Line: 619, Value: "bytes.TrimSuffix($lit, $s)"},
- {Line: 620, Value: "strings.Split($lit, $s)"},
- {Line: 621, Value: "bytes.Split($lit, $s)"},
+ {Line: 608, Value: "strings.HasPrefix($lit, $s)"},
+ {Line: 609, Value: "bytes.HasPrefix($lit, $s)"},
+ {Line: 610, Value: "strings.HasSuffix($lit, $s)"},
+ {Line: 611, Value: "bytes.HasSuffix($lit, $s)"},
+ {Line: 612, Value: "strings.Contains($lit, $s)"},
+ {Line: 613, Value: "bytes.Contains($lit, $s)"},
+ {Line: 614, Value: "strings.TrimPrefix($lit, $s)"},
+ {Line: 615, Value: "bytes.TrimPrefix($lit, $s)"},
+ {Line: 616, Value: "strings.TrimSuffix($lit, $s)"},
+ {Line: 617, Value: "bytes.TrimSuffix($lit, $s)"},
+ {Line: 618, Value: "strings.Split($lit, $s)"},
+ {Line: 619, Value: "bytes.Split($lit, $s)"},
},
ReportTemplate: "$lit and $s arguments order looks reversed",
WhereExpr: ir.FilterExpr{
- Line: 622,
+ Line: 620,
Op: ir.FilterAndOp,
Src: "(m[\"lit\"].Const || m[\"lit\"].ConstSlice) &&\n\t!(m[\"s\"].Const || m[\"s\"].ConstSlice) &&\n\t!m[\"lit\"].Node.Is(`Ident`)",
Args: []ir.FilterExpr{
{
- Line: 622,
+ Line: 620,
Op: ir.FilterAndOp,
Src: "(m[\"lit\"].Const || m[\"lit\"].ConstSlice) &&\n\t!(m[\"s\"].Const || m[\"s\"].ConstSlice)",
Args: []ir.FilterExpr{
{
- Line: 622,
+ Line: 620,
Op: ir.FilterOrOp,
Src: "(m[\"lit\"].Const || m[\"lit\"].ConstSlice)",
Args: []ir.FilterExpr{
{
- Line: 622,
+ Line: 620,
Op: ir.FilterVarConstOp,
Src: "m[\"lit\"].Const",
Value: "lit",
},
{
- Line: 622,
+ Line: 620,
Op: ir.FilterVarConstSliceOp,
Src: "m[\"lit\"].ConstSlice",
Value: "lit",
@@ -1897,22 +1914,22 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 623,
+ Line: 621,
Op: ir.FilterNotOp,
Src: "!(m[\"s\"].Const || m[\"s\"].ConstSlice)",
Args: []ir.FilterExpr{{
- Line: 623,
+ Line: 621,
Op: ir.FilterOrOp,
Src: "(m[\"s\"].Const || m[\"s\"].ConstSlice)",
Args: []ir.FilterExpr{
{
- Line: 623,
+ Line: 621,
Op: ir.FilterVarConstOp,
Src: "m[\"s\"].Const",
Value: "s",
},
{
- Line: 623,
+ Line: 621,
Op: ir.FilterVarConstSliceOp,
Src: "m[\"s\"].ConstSlice",
Value: "s",
@@ -1923,15 +1940,15 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 624,
+ Line: 622,
Op: ir.FilterNotOp,
Src: "!m[\"lit\"].Node.Is(`Ident`)",
Args: []ir.FilterExpr{{
- Line: 624,
+ Line: 622,
Op: ir.FilterVarNodeIsOp,
Src: "m[\"lit\"].Node.Is(`Ident`)",
Value: "lit",
- Args: []ir.FilterExpr{{Line: 624, Op: ir.FilterStringOp, Src: "`Ident`", Value: "Ident"}},
+ Args: []ir.FilterExpr{{Line: 622, Op: ir.FilterStringOp, Src: "`Ident`", Value: "Ident"}},
}},
},
},
@@ -1939,7 +1956,7 @@ var PrecompiledRules = &ir.File{
}},
},
{
- Line: 632,
+ Line: 630,
Name: "stringConcatSimplify",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -1948,27 +1965,27 @@ var PrecompiledRules = &ir.File{
DocAfter: "x + \"_\" + y",
Rules: []ir.Rule{
{
- Line: 633,
- SyntaxPatterns: []ir.PatternString{{Line: 633, Value: "strings.Join([]string{$x, $y}, \"\")"}},
+ Line: 631,
+ SyntaxPatterns: []ir.PatternString{{Line: 631, Value: "strings.Join([]string{$x, $y}, \"\")"}},
ReportTemplate: "suggestion: $x + $y",
SuggestTemplate: "$x + $y",
},
{
- Line: 634,
- SyntaxPatterns: []ir.PatternString{{Line: 634, Value: "strings.Join([]string{$x, $y, $z}, \"\")"}},
+ Line: 632,
+ SyntaxPatterns: []ir.PatternString{{Line: 632, Value: "strings.Join([]string{$x, $y, $z}, \"\")"}},
ReportTemplate: "suggestion: $x + $y + $z",
SuggestTemplate: "$x + $y + $z",
},
{
- Line: 635,
- SyntaxPatterns: []ir.PatternString{{Line: 635, Value: "strings.Join([]string{$x, $y}, $glue)"}},
+ Line: 633,
+ SyntaxPatterns: []ir.PatternString{{Line: 633, Value: "strings.Join([]string{$x, $y}, $glue)"}},
ReportTemplate: "suggestion: $x + $glue + $y",
SuggestTemplate: "$x + $glue + $y",
},
},
},
{
- Line: 642,
+ Line: 640,
Name: "timeExprSimplify",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -1977,39 +1994,39 @@ var PrecompiledRules = &ir.File{
DocAfter: "t.UnixMilli()",
Rules: []ir.Rule{
{
- Line: 647,
- SyntaxPatterns: []ir.PatternString{{Line: 647, Value: "$t.Unix() / 1000"}},
+ Line: 645,
+ SyntaxPatterns: []ir.PatternString{{Line: 645, Value: "$t.Unix() / 1000"}},
ReportTemplate: "use $t.UnixMilli() instead of $$",
SuggestTemplate: "$t.UnixMilli()",
WhereExpr: ir.FilterExpr{
- Line: 648,
+ Line: 646,
Op: ir.FilterAndOp,
Src: "m.GoVersion().GreaterEqThan(\"1.17\") && isTime(m[\"t\"])",
Args: []ir.FilterExpr{
{
- Line: 648,
+ Line: 646,
Op: ir.FilterGoVersionGreaterEqThanOp,
Src: "m.GoVersion().GreaterEqThan(\"1.17\")",
Value: "1.17",
},
{
- Line: 648,
+ Line: 646,
Op: ir.FilterOrOp,
Src: "isTime(m[\"t\"])",
Args: []ir.FilterExpr{
{
- Line: 648,
+ Line: 646,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"t\"].Type.Is(`time.Time`)",
Value: "t",
- Args: []ir.FilterExpr{{Line: 644, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
+ Args: []ir.FilterExpr{{Line: 642, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
},
{
- Line: 648,
+ Line: 646,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"t\"].Type.Is(`*time.Time`)",
Value: "t",
- Args: []ir.FilterExpr{{Line: 644, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
+ Args: []ir.FilterExpr{{Line: 642, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
},
},
},
@@ -2017,39 +2034,39 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 652,
- SyntaxPatterns: []ir.PatternString{{Line: 652, Value: "$t.UnixNano() * 1000"}},
+ Line: 650,
+ SyntaxPatterns: []ir.PatternString{{Line: 650, Value: "$t.UnixNano() * 1000"}},
ReportTemplate: "use $t.UnixMicro() instead of $$",
SuggestTemplate: "$t.UnixMicro()",
WhereExpr: ir.FilterExpr{
- Line: 653,
+ Line: 651,
Op: ir.FilterAndOp,
Src: "m.GoVersion().GreaterEqThan(\"1.17\") && isTime(m[\"t\"])",
Args: []ir.FilterExpr{
{
- Line: 653,
+ Line: 651,
Op: ir.FilterGoVersionGreaterEqThanOp,
Src: "m.GoVersion().GreaterEqThan(\"1.17\")",
Value: "1.17",
},
{
- Line: 653,
+ Line: 651,
Op: ir.FilterOrOp,
Src: "isTime(m[\"t\"])",
Args: []ir.FilterExpr{
{
- Line: 653,
+ Line: 651,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"t\"].Type.Is(`time.Time`)",
Value: "t",
- Args: []ir.FilterExpr{{Line: 644, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
+ Args: []ir.FilterExpr{{Line: 642, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
},
{
- Line: 653,
+ Line: 651,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"t\"].Type.Is(`*time.Time`)",
Value: "t",
- Args: []ir.FilterExpr{{Line: 644, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
+ Args: []ir.FilterExpr{{Line: 642, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
},
},
},
@@ -2059,7 +2076,7 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 662,
+ Line: 660,
Name: "timeCmpSimplify",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -2068,55 +2085,55 @@ var PrecompiledRules = &ir.File{
DocAfter: "t.After(tt)",
Rules: []ir.Rule{
{
- Line: 667,
- SyntaxPatterns: []ir.PatternString{{Line: 667, Value: "!$t.Before($tt)"}},
+ Line: 665,
+ SyntaxPatterns: []ir.PatternString{{Line: 665, Value: "!$t.Before($tt)"}},
ReportTemplate: "suggestion: $t.After($tt)",
SuggestTemplate: "$t.After($tt)",
WhereExpr: ir.FilterExpr{
- Line: 668,
+ Line: 666,
Op: ir.FilterOrOp,
Src: "isTime(m[\"t\"])",
Args: []ir.FilterExpr{
{
- Line: 668,
+ Line: 666,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"t\"].Type.Is(`time.Time`)",
Value: "t",
- Args: []ir.FilterExpr{{Line: 664, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
+ Args: []ir.FilterExpr{{Line: 662, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
},
{
- Line: 668,
+ Line: 666,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"t\"].Type.Is(`*time.Time`)",
Value: "t",
- Args: []ir.FilterExpr{{Line: 664, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
+ Args: []ir.FilterExpr{{Line: 662, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
},
},
},
},
{
- Line: 671,
- SyntaxPatterns: []ir.PatternString{{Line: 671, Value: "!$t.After($tt)"}},
+ Line: 669,
+ SyntaxPatterns: []ir.PatternString{{Line: 669, Value: "!$t.After($tt)"}},
ReportTemplate: "suggestion: $t.Before($tt)",
SuggestTemplate: "$t.Before($tt)",
WhereExpr: ir.FilterExpr{
- Line: 672,
+ Line: 670,
Op: ir.FilterOrOp,
Src: "isTime(m[\"t\"])",
Args: []ir.FilterExpr{
{
- Line: 672,
+ Line: 670,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"t\"].Type.Is(`time.Time`)",
Value: "t",
- Args: []ir.FilterExpr{{Line: 664, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
+ Args: []ir.FilterExpr{{Line: 662, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
},
{
- Line: 672,
+ Line: 670,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"t\"].Type.Is(`*time.Time`)",
Value: "t",
- Args: []ir.FilterExpr{{Line: 664, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
+ Args: []ir.FilterExpr{{Line: 662, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
},
},
},
@@ -2124,7 +2141,7 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 680,
+ Line: 678,
Name: "exposedSyncMutex",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -2133,57 +2150,57 @@ var PrecompiledRules = &ir.File{
DocAfter: "type Foo struct{ ...; mu sync.Mutex; ... }",
Rules: []ir.Rule{
{
- Line: 685,
- SyntaxPatterns: []ir.PatternString{{Line: 685, Value: "type $x struct { $*_; sync.Mutex; $*_ }"}},
+ Line: 683,
+ SyntaxPatterns: []ir.PatternString{{Line: 683, Value: "type $x struct { $*_; sync.Mutex; $*_ }"}},
ReportTemplate: "don't embed sync.Mutex",
WhereExpr: ir.FilterExpr{
- Line: 686,
+ Line: 684,
Op: ir.FilterVarTextMatchesOp,
Src: "isExported(m[\"x\"])",
Value: "x",
- Args: []ir.FilterExpr{{Line: 682, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
+ Args: []ir.FilterExpr{{Line: 680, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
},
},
{
- Line: 689,
- SyntaxPatterns: []ir.PatternString{{Line: 689, Value: "type $x struct { $*_; *sync.Mutex; $*_ }"}},
+ Line: 687,
+ SyntaxPatterns: []ir.PatternString{{Line: 687, Value: "type $x struct { $*_; *sync.Mutex; $*_ }"}},
ReportTemplate: "don't embed *sync.Mutex",
WhereExpr: ir.FilterExpr{
- Line: 690,
+ Line: 688,
Op: ir.FilterVarTextMatchesOp,
Src: "isExported(m[\"x\"])",
Value: "x",
- Args: []ir.FilterExpr{{Line: 682, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
+ Args: []ir.FilterExpr{{Line: 680, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
},
},
{
- Line: 693,
- SyntaxPatterns: []ir.PatternString{{Line: 693, Value: "type $x struct { $*_; sync.RWMutex; $*_ }"}},
+ Line: 691,
+ SyntaxPatterns: []ir.PatternString{{Line: 691, Value: "type $x struct { $*_; sync.RWMutex; $*_ }"}},
ReportTemplate: "don't embed sync.RWMutex",
WhereExpr: ir.FilterExpr{
- Line: 694,
+ Line: 692,
Op: ir.FilterVarTextMatchesOp,
Src: "isExported(m[\"x\"])",
Value: "x",
- Args: []ir.FilterExpr{{Line: 682, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
+ Args: []ir.FilterExpr{{Line: 680, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
},
},
{
- Line: 697,
- SyntaxPatterns: []ir.PatternString{{Line: 697, Value: "type $x struct { $*_; *sync.RWMutex; $*_ }"}},
+ Line: 695,
+ SyntaxPatterns: []ir.PatternString{{Line: 695, Value: "type $x struct { $*_; *sync.RWMutex; $*_ }"}},
ReportTemplate: "don't embed *sync.RWMutex",
WhereExpr: ir.FilterExpr{
- Line: 698,
+ Line: 696,
Op: ir.FilterVarTextMatchesOp,
Src: "isExported(m[\"x\"])",
Value: "x",
- Args: []ir.FilterExpr{{Line: 682, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
+ Args: []ir.FilterExpr{{Line: 680, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
},
},
},
},
{
- Line: 706,
+ Line: 704,
Name: "badSorting",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -2192,48 +2209,48 @@ var PrecompiledRules = &ir.File{
DocAfter: "sort.Strings(xs)",
Rules: []ir.Rule{
{
- Line: 707,
- SyntaxPatterns: []ir.PatternString{{Line: 707, Value: "$x = sort.IntSlice($x)"}},
+ Line: 705,
+ SyntaxPatterns: []ir.PatternString{{Line: 705, Value: "$x = sort.IntSlice($x)"}},
ReportTemplate: "suspicious sort.IntSlice usage, maybe sort.Ints was intended?",
SuggestTemplate: "sort.Ints($x)",
WhereExpr: ir.FilterExpr{
- Line: 708,
+ Line: 706,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`[]int`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 708, Op: ir.FilterStringOp, Src: "`[]int`", Value: "[]int"}},
+ Args: []ir.FilterExpr{{Line: 706, Op: ir.FilterStringOp, Src: "`[]int`", Value: "[]int"}},
},
},
{
- Line: 712,
- SyntaxPatterns: []ir.PatternString{{Line: 712, Value: "$x = sort.Float64Slice($x)"}},
+ Line: 710,
+ SyntaxPatterns: []ir.PatternString{{Line: 710, Value: "$x = sort.Float64Slice($x)"}},
ReportTemplate: "suspicious sort.Float64s usage, maybe sort.Float64s was intended?",
SuggestTemplate: "sort.Float64s($x)",
WhereExpr: ir.FilterExpr{
- Line: 713,
+ Line: 711,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`[]float64`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 713, Op: ir.FilterStringOp, Src: "`[]float64`", Value: "[]float64"}},
+ Args: []ir.FilterExpr{{Line: 711, Op: ir.FilterStringOp, Src: "`[]float64`", Value: "[]float64"}},
},
},
{
- Line: 717,
- SyntaxPatterns: []ir.PatternString{{Line: 717, Value: "$x = sort.StringSlice($x)"}},
+ Line: 715,
+ SyntaxPatterns: []ir.PatternString{{Line: 715, Value: "$x = sort.StringSlice($x)"}},
ReportTemplate: "suspicious sort.StringSlice usage, maybe sort.Strings was intended?",
SuggestTemplate: "sort.Strings($x)",
WhereExpr: ir.FilterExpr{
- Line: 718,
+ Line: 716,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`[]string`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 718, Op: ir.FilterStringOp, Src: "`[]string`", Value: "[]string"}},
+ Args: []ir.FilterExpr{{Line: 716, Op: ir.FilterStringOp, Src: "`[]string`", Value: "[]string"}},
},
},
},
},
{
- Line: 727,
+ Line: 725,
Name: "externalErrorReassign",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -2241,34 +2258,34 @@ var PrecompiledRules = &ir.File{
DocBefore: "io.EOF = nil",
DocAfter: "/* don't do it */",
Rules: []ir.Rule{{
- Line: 728,
- SyntaxPatterns: []ir.PatternString{{Line: 728, Value: "$pkg.$err = $x"}},
+ Line: 726,
+ SyntaxPatterns: []ir.PatternString{{Line: 726, Value: "$pkg.$err = $x"}},
ReportTemplate: "suspicious reassigment of error from another package",
WhereExpr: ir.FilterExpr{
- Line: 729,
+ Line: 727,
Op: ir.FilterAndOp,
Src: "m[\"err\"].Type.Is(`error`) && m[\"pkg\"].Object.Is(`PkgName`)",
Args: []ir.FilterExpr{
{
- Line: 729,
+ Line: 727,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"err\"].Type.Is(`error`)",
Value: "err",
- Args: []ir.FilterExpr{{Line: 729, Op: ir.FilterStringOp, Src: "`error`", Value: "error"}},
+ Args: []ir.FilterExpr{{Line: 727, Op: ir.FilterStringOp, Src: "`error`", Value: "error"}},
},
{
- Line: 729,
+ Line: 727,
Op: ir.FilterVarObjectIsOp,
Src: "m[\"pkg\"].Object.Is(`PkgName`)",
Value: "pkg",
- Args: []ir.FilterExpr{{Line: 729, Op: ir.FilterStringOp, Src: "`PkgName`", Value: "PkgName"}},
+ Args: []ir.FilterExpr{{Line: 727, Op: ir.FilterStringOp, Src: "`PkgName`", Value: "PkgName"}},
},
},
},
}},
},
{
- Line: 737,
+ Line: 735,
Name: "emptyDecl",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -2277,24 +2294,24 @@ var PrecompiledRules = &ir.File{
DocAfter: "/* nothing */",
Rules: []ir.Rule{
{
- Line: 738,
- SyntaxPatterns: []ir.PatternString{{Line: 738, Value: "var()"}},
+ Line: 736,
+ SyntaxPatterns: []ir.PatternString{{Line: 736, Value: "var()"}},
ReportTemplate: "empty var() block",
},
{
- Line: 739,
- SyntaxPatterns: []ir.PatternString{{Line: 739, Value: "const()"}},
+ Line: 737,
+ SyntaxPatterns: []ir.PatternString{{Line: 737, Value: "const()"}},
ReportTemplate: "empty const() block",
},
{
- Line: 740,
- SyntaxPatterns: []ir.PatternString{{Line: 740, Value: "type()"}},
+ Line: 738,
+ SyntaxPatterns: []ir.PatternString{{Line: 738, Value: "type()"}},
ReportTemplate: "empty type() block",
},
},
},
{
- Line: 747,
+ Line: 745,
Name: "dynamicFmtString",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -2303,16 +2320,16 @@ var PrecompiledRules = &ir.File{
DocAfter: "fmt.Errorf(\"%s\", msg)",
Rules: []ir.Rule{
{
- Line: 748,
- SyntaxPatterns: []ir.PatternString{{Line: 748, Value: "fmt.Errorf($f)"}},
+ Line: 746,
+ SyntaxPatterns: []ir.PatternString{{Line: 746, Value: "fmt.Errorf($f)"}},
ReportTemplate: "use errors.New($f) or fmt.Errorf(\"%s\", $f) instead",
SuggestTemplate: "errors.New($f)",
WhereExpr: ir.FilterExpr{
- Line: 749,
+ Line: 747,
Op: ir.FilterNotOp,
Src: "!m[\"f\"].Const",
Args: []ir.FilterExpr{{
- Line: 749,
+ Line: 747,
Op: ir.FilterVarConstOp,
Src: "m[\"f\"].Const",
Value: "f",
@@ -2320,15 +2337,15 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 753,
- SyntaxPatterns: []ir.PatternString{{Line: 753, Value: "fmt.Errorf($f($*args))"}},
+ Line: 751,
+ SyntaxPatterns: []ir.PatternString{{Line: 751, Value: "fmt.Errorf($f($*args))"}},
ReportTemplate: "use errors.New($f($*args)) or fmt.Errorf(\"%s\", $f($*args)) instead",
SuggestTemplate: "errors.New($f($*args))",
},
},
},
{
- Line: 762,
+ Line: 760,
Name: "stringsCompare",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -2337,31 +2354,88 @@ var PrecompiledRules = &ir.File{
DocAfter: "x < y",
Rules: []ir.Rule{
{
- Line: 763,
- SyntaxPatterns: []ir.PatternString{{Line: 763, Value: "strings.Compare($s1, $s2) == 0"}},
+ Line: 761,
+ SyntaxPatterns: []ir.PatternString{{Line: 761, Value: "strings.Compare($s1, $s2) == 0"}},
ReportTemplate: "suggestion: $s1 == $s2",
SuggestTemplate: "$s1 == $s2",
},
{
- Line: 766,
+ Line: 764,
SyntaxPatterns: []ir.PatternString{
- {Line: 766, Value: "strings.Compare($s1, $s2) == -1"},
- {Line: 767, Value: "strings.Compare($s1, $s2) < 0"},
+ {Line: 764, Value: "strings.Compare($s1, $s2) == -1"},
+ {Line: 765, Value: "strings.Compare($s1, $s2) < 0"},
},
ReportTemplate: "suggestion: $s1 < $s2",
SuggestTemplate: "$s1 < $s2",
},
{
- Line: 770,
+ Line: 768,
SyntaxPatterns: []ir.PatternString{
- {Line: 770, Value: "strings.Compare($s1, $s2) == 1"},
- {Line: 771, Value: "strings.Compare($s1, $s2) > 0"},
+ {Line: 768, Value: "strings.Compare($s1, $s2) == 1"},
+ {Line: 769, Value: "strings.Compare($s1, $s2) > 0"},
},
ReportTemplate: "suggestion: $s1 > $s2",
SuggestTemplate: "$s1 > $s2",
},
},
},
+ {
+ Line: 777,
+ Name: "uncheckedInlineErr",
+ MatcherName: "m",
+ DocTags: []string{"diagnostic", "experimental"},
+ DocSummary: "Detects unchecked errors in if statements",
+ DocBefore: "if err := expr(); err2 != nil { /*...*/ }",
+ DocAfter: "if err := expr(); err != nil { /*...*/ }",
+ Rules: []ir.Rule{{
+ Line: 778,
+ SyntaxPatterns: []ir.PatternString{
+ {Line: 779, Value: "if $err := $_($*_); $err2 != nil { $*_ }"},
+ {Line: 780, Value: "if $err = $_($*_); $err2 != nil { $*_ }"},
+ {Line: 781, Value: "if $*_, $err := $_($*_); $err2 != nil { $*_ }"},
+ {Line: 782, Value: "if $*_, $err = $_($*_); $err2 != nil { $*_ }"},
+ },
+ ReportTemplate: "$err error is unchecked, maybe intended to check it instead of $err2",
+ WhereExpr: ir.FilterExpr{
+ Line: 783,
+ Op: ir.FilterAndOp,
+ Src: "m[\"err\"].Type.Implements(\"error\") && m[\"err2\"].Type.Implements(\"error\") &&\n\tm[\"err\"].Text != m[\"err2\"].Text",
+ Args: []ir.FilterExpr{
+ {
+ Line: 783,
+ Op: ir.FilterAndOp,
+ Src: "m[\"err\"].Type.Implements(\"error\") && m[\"err2\"].Type.Implements(\"error\")",
+ Args: []ir.FilterExpr{
+ {
+ Line: 783,
+ Op: ir.FilterVarTypeImplementsOp,
+ Src: "m[\"err\"].Type.Implements(\"error\")",
+ Value: "err",
+ Args: []ir.FilterExpr{{Line: 783, Op: ir.FilterStringOp, Src: "\"error\"", Value: "error"}},
+ },
+ {
+ Line: 783,
+ Op: ir.FilterVarTypeImplementsOp,
+ Src: "m[\"err2\"].Type.Implements(\"error\")",
+ Value: "err2",
+ Args: []ir.FilterExpr{{Line: 783, Op: ir.FilterStringOp, Src: "\"error\"", Value: "error"}},
+ },
+ },
+ },
+ {
+ Line: 784,
+ Op: ir.FilterNeqOp,
+ Src: "m[\"err\"].Text != m[\"err2\"].Text",
+ Args: []ir.FilterExpr{
+ {Line: 784, Op: ir.FilterVarTextOp, Src: "m[\"err\"].Text", Value: "err"},
+ {Line: 784, Op: ir.FilterVarTextOp, Src: "m[\"err2\"].Text", Value: "err2"},
+ },
+ },
+ },
+ },
+ LocationVar: "err",
+ }},
+ },
},
}
diff --git a/vendor/github.com/go-critic/go-critic/framework/linter/linter.go b/vendor/github.com/go-critic/go-critic/framework/linter/linter.go
index 750ff7cd9..8573ace30 100644
--- a/vendor/github.com/go-critic/go-critic/framework/linter/linter.go
+++ b/vendor/github.com/go-critic/go-critic/framework/linter/linter.go
@@ -6,7 +6,6 @@ import (
"go/types"
"github.com/go-toolsmith/astfmt"
- "golang.org/x/exp/typeparams"
)
// CheckerCollection provides additional information for a group of checkers.
@@ -141,9 +140,7 @@ type QuickFix struct {
// Warning represents issue that is found by checker.
type Warning struct {
- // Node is an AST node that caused warning to trigger.
- // Can be used to obtain proper error location.
- Node ast.Node
+ Pos token.Pos
// Text is warning message without source location info.
Text string
@@ -279,17 +276,27 @@ type CheckerContext struct {
// Warn adds a Warning to checker output.
func (ctx *CheckerContext) Warn(node ast.Node, format string, args ...interface{}) {
+ ctx.WarnWithPos(node.Pos(), format, args...)
+}
+
+// WarnFixable emits a warning with a fix suggestion provided by the caller.
+func (ctx *CheckerContext) WarnFixable(node ast.Node, fix QuickFix, format string, args ...interface{}) {
+ ctx.WarnFixableWithPos(node.Pos(), fix, format, args...)
+}
+
+// WarnWithPos adds a Warning to checker output. Useful for ruleguard's Report func.
+func (ctx *CheckerContext) WarnWithPos(pos token.Pos, format string, args ...interface{}) {
ctx.warnings = append(ctx.warnings, Warning{
Text: ctx.printer.Sprintf(format, args...),
- Node: node,
+ Pos: pos,
})
}
-// WarnFixable emits a warning with a fix suggestion provided by the caller.
-func (ctx *CheckerContext) WarnFixable(node ast.Node, fix QuickFix, format string, args ...interface{}) {
+// WarnFixableWithPos adds a Warning to checker output. Useful for ruleguard's Report func.
+func (ctx *CheckerContext) WarnFixableWithPos(pos token.Pos, fix QuickFix, format string, args ...interface{}) {
ctx.warnings = append(ctx.warnings, Warning{
Text: ctx.printer.Sprintf(format, args...),
- Node: node,
+ Pos: pos,
Suggestion: fix,
})
}
@@ -319,7 +326,10 @@ func (ctx *CheckerContext) TypeOf(x ast.Expr) types.Type {
//
// Unlike SizesInfo.SizeOf, it will not panic on generic types.
func (ctx *CheckerContext) SizeOf(typ types.Type) (int64, bool) {
- if _, ok := typ.(*typeparams.TypeParam); ok {
+ if _, ok := typ.(*types.TypeParam); ok {
+ return 0, false
+ }
+ if named, ok := typ.(*types.Named); ok && named.TypeParams() != nil {
return 0, false
}
return ctx.SizesInfo.Sizeof(typ), true