aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-critic
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2024-03-04 17:40:11 +0000
committerTaras Madan <tarasmadan@google.com>2024-03-04 18:34:55 +0000
commit5fc5366972c874b919f93165bb4ed4e2bcb7c350 (patch)
tree287c3361a0dee0c72af80d9a1a66714a06e98a62 /vendor/github.com/go-critic
parent1be5ce38a9059c356eb193a8c34d60d61c9fc31f (diff)
mod: bump github.com/golangci/golangci-lint from 1.55.2 to 1.56.2
Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.55.2 to 1.56.2. - [Release notes](https://github.com/golangci/golangci-lint/releases) - [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md) - [Commits](https://github.com/golangci/golangci-lint/compare/v1.55.2...v1.56.2) --- updated-dependencies: - dependency-name: github.com/golangci/golangci-lint dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
Diffstat (limited to 'vendor/github.com/go-critic')
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/commentedOutCode_checker.go11
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/dupImports_checker.go2
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/flagName_checker.go6
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/hugeParam_checker.go20
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/internal/lintutil/astflow.go2
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/mapKey_checker.go2
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/rulesdata/rulesdata.go1325
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/typeUnparen_checker.go2
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/unlambda_checker.go19
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/unnecessaryDefer_checker.go2
-rw-r--r--vendor/github.com/go-critic/go-critic/checkers/utils.go2
11 files changed, 662 insertions, 731 deletions
diff --git a/vendor/github.com/go-critic/go-critic/checkers/commentedOutCode_checker.go b/vendor/github.com/go-critic/go-critic/checkers/commentedOutCode_checker.go
index 402ba3306..8595b7951 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/commentedOutCode_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/commentedOutCode_checker.go
@@ -6,6 +6,7 @@ import (
"go/token"
"regexp"
"strings"
+ "unicode/utf8"
"github.com/go-critic/go-critic/checkers/internal/astwalk"
"github.com/go-critic/go-critic/linter"
@@ -18,6 +19,12 @@ func init() {
info.Name = "commentedOutCode"
info.Tags = []string{linter.DiagnosticTag, linter.ExperimentalTag}
info.Summary = "Detects commented-out code inside function bodies"
+ info.Params = linter.CheckerParams{
+ "minLength": {
+ Value: 15,
+ Usage: "min length of the comment that triggers a warning",
+ },
+ }
info.Before = `
// fmt.Println("Debugging hard")
foo(1, 2)`
@@ -27,6 +34,7 @@ foo(1, 2)`
return astwalk.WalkerForLocalComment(&commentedOutCodeChecker{
ctx: ctx,
notQuiteFuncCall: regexp.MustCompile(`\w+\s+\([^)]*\)\s*$`),
+ minLength: info.Params.Int("minLength"),
}), nil
})
}
@@ -37,6 +45,7 @@ type commentedOutCodeChecker struct {
fn *ast.FuncDecl
notQuiteFuncCall *regexp.Regexp
+ minLength int
}
func (c *commentedOutCodeChecker) EnterFunc(fn *ast.FuncDecl) bool {
@@ -69,7 +78,7 @@ func (c *commentedOutCodeChecker) VisitLocalComment(cg *ast.CommentGroup) {
// Some very short comment that can be skipped.
// Usually triggering on these results in false positive.
// Unless there is a very popular call like print/println.
- cond := len(s) < len("quite too short") &&
+ cond := utf8.RuneCountInString(s) < c.minLength &&
!strings.Contains(s, "print") &&
!strings.Contains(s, "fmt.") &&
!strings.Contains(s, "log.")
diff --git a/vendor/github.com/go-critic/go-critic/checkers/dupImports_checker.go b/vendor/github.com/go-critic/go-critic/checkers/dupImports_checker.go
index 19079871f..ed674eb85 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/dupImports_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/dupImports_checker.go
@@ -15,7 +15,7 @@ func init() {
info.Before = `
import (
"fmt"
- priting "fmt" // Imported the second time
+ printing "fmt" // Imported the second time
)`
info.After = `
import(
diff --git a/vendor/github.com/go-critic/go-critic/checkers/flagName_checker.go b/vendor/github.com/go-critic/go-critic/checkers/flagName_checker.go
index 98b76e261..701066860 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/flagName_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/flagName_checker.go
@@ -64,7 +64,7 @@ func (c *flagNameChecker) checkFlagName(call *ast.CallExpr, arg ast.Expr) {
case name == "":
c.warnEmpty(call)
case strings.HasPrefix(name, "-"):
- c.warnHypenPrefix(call, name)
+ c.warnHyphenPrefix(call, name)
case strings.Contains(name, "="):
c.warnEq(call, name)
case strings.Contains(name, " "):
@@ -76,8 +76,8 @@ func (c *flagNameChecker) warnEmpty(cause ast.Node) {
c.ctx.Warn(cause, "empty flag name")
}
-func (c *flagNameChecker) warnHypenPrefix(cause ast.Node, name string) {
- c.ctx.Warn(cause, "flag name %q should not start with a hypen", name)
+func (c *flagNameChecker) warnHyphenPrefix(cause ast.Node, name string) {
+ c.ctx.Warn(cause, "flag name %q should not start with a hyphen", name)
}
func (c *flagNameChecker) warnEq(cause ast.Node, name string) {
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 3b7f1d12b..7b7a3c538 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,6 +5,8 @@ import (
"github.com/go-critic/go-critic/checkers/internal/astwalk"
"github.com/go-critic/go-critic/linter"
+
+ "github.com/go-toolsmith/astcast"
)
func init() {
@@ -39,12 +41,30 @@ type hugeParamChecker struct {
func (c *hugeParamChecker) VisitFuncDecl(decl *ast.FuncDecl) {
// TODO(quasilyte): maybe it's worthwhile to permit skipping
// test files for this checker?
+ if c.isImplementStringer(decl) {
+ return
+ }
+
if decl.Recv != nil {
c.checkParams(decl.Recv.List)
}
c.checkParams(decl.Type.Params.List)
}
+// isImplementStringer check method signature is: String() string.
+func (*hugeParamChecker) isImplementStringer(decl *ast.FuncDecl) bool {
+ if decl.Recv != nil &&
+ decl.Name.Name == "String" &&
+ decl.Type != nil &&
+ len(decl.Type.Params.List) == 0 &&
+ len(decl.Type.Results.List) == 1 &&
+ astcast.ToIdent(decl.Type.Results.List[0].Type).Name == "string" {
+ return true
+ }
+
+ return false
+}
+
func (c *hugeParamChecker) checkParams(params []*ast.Field) {
for _, p := range params {
for _, id := range p.Names {
diff --git a/vendor/github.com/go-critic/go-critic/checkers/internal/lintutil/astflow.go b/vendor/github.com/go-critic/go-critic/checkers/internal/lintutil/astflow.go
index 63d181e5e..f64907d69 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/internal/lintutil/astflow.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/internal/lintutil/astflow.go
@@ -18,7 +18,7 @@ import (
//
// If proven really useful, can be moved to go-toolsmith library.
-// IsImmutable reports whether n can be midified through any operation.
+// IsImmutable reports whether n can be modified through any operation.
func IsImmutable(info *types.Info, n ast.Expr) bool {
if astp.IsBasicLit(n) {
return true
diff --git a/vendor/github.com/go-critic/go-critic/checkers/mapKey_checker.go b/vendor/github.com/go-critic/go-critic/checkers/mapKey_checker.go
index ebc61c12a..2885dc725 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/mapKey_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/mapKey_checker.go
@@ -117,7 +117,7 @@ func (c *mapKeyChecker) checkWhitespace(lit *ast.CompositeLit) {
}
func (c *mapKeyChecker) warnWhitespace(key ast.Node) {
- c.ctx.Warn(key, "suspucious whitespace in %s key", key)
+ c.ctx.Warn(key, "suspicious whitespace in %s key", key)
}
func (c *mapKeyChecker) warnDupKey(key ast.Node) {
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 503118c7e..4ab31076f 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
@@ -363,7 +363,7 @@ var PrecompiledRules = &ir.File{
Line: 114,
Name: "sloppyLen",
MatcherName: "m",
- DocTags: []string{"style"},
+ DocTags: []string{"diagnostic"},
DocSummary: "Detects usage of `len` when result is obvious or doesn't make sense",
DocBefore: "len(arr) <= 0",
DocAfter: "len(arr) == 0",
@@ -493,21 +493,45 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 164,
- SyntaxPatterns: []ir.PatternString{{Line: 164, Value: "len($s) == 0"}},
+ Line: 163,
+ SyntaxPatterns: []ir.PatternString{{Line: 163, Value: "len($s) > 0"}},
+ ReportTemplate: "replace `$$` with `$s != \"\"`",
+ WhereExpr: ir.FilterExpr{
+ Line: 164,
+ Op: ir.FilterVarTypeIsOp,
+ Src: "m[\"s\"].Type.Is(`string`)",
+ Value: "s",
+ Args: []ir.FilterExpr{{Line: 164, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ },
+ },
+ {
+ Line: 167,
+ SyntaxPatterns: []ir.PatternString{{Line: 167, Value: "len($s) == 0"}},
+ ReportTemplate: "replace `$$` with `$s == \"\"`",
+ WhereExpr: ir.FilterExpr{
+ Line: 168,
+ Op: ir.FilterVarTypeIsOp,
+ Src: "m[\"s\"].Type.Is(`string`)",
+ Value: "s",
+ Args: []ir.FilterExpr{{Line: 168, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ },
+ },
+ {
+ Line: 170,
+ SyntaxPatterns: []ir.PatternString{{Line: 170, Value: "len($s) <= 0"}},
ReportTemplate: "replace `$$` with `$s == \"\"`",
WhereExpr: ir.FilterExpr{
- Line: 165,
+ Line: 171,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`string`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 165, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 171, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
},
},
},
{
- Line: 173,
+ Line: 179,
Name: "stringXbytes",
MatcherName: "m",
DocTags: []string{"performance"},
@@ -516,180 +540,180 @@ var PrecompiledRules = &ir.File{
DocAfter: "copy(b, s)",
Rules: []ir.Rule{
{
- Line: 174,
- SyntaxPatterns: []ir.PatternString{{Line: 174, Value: "copy($_, []byte($s))"}},
+ Line: 180,
+ SyntaxPatterns: []ir.PatternString{{Line: 180, Value: "copy($_, []byte($s))"}},
ReportTemplate: "can simplify `[]byte($s)` to `$s`",
},
{
- Line: 176,
- SyntaxPatterns: []ir.PatternString{{Line: 176, Value: "string($b) == \"\""}},
+ Line: 182,
+ SyntaxPatterns: []ir.PatternString{{Line: 182, Value: "string($b) == \"\""}},
ReportTemplate: "suggestion: len($b) == 0",
SuggestTemplate: "len($b) == 0",
WhereExpr: ir.FilterExpr{
- Line: 176,
+ Line: 182,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"b\"].Type.Is(`[]byte`)",
Value: "b",
- Args: []ir.FilterExpr{{Line: 176, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 182, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
},
{
- Line: 177,
- SyntaxPatterns: []ir.PatternString{{Line: 177, Value: "string($b) != \"\""}},
+ Line: 183,
+ SyntaxPatterns: []ir.PatternString{{Line: 183, Value: "string($b) != \"\""}},
ReportTemplate: "suggestion: len($b) != 0",
SuggestTemplate: "len($b) != 0",
WhereExpr: ir.FilterExpr{
- Line: 177,
+ Line: 183,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"b\"].Type.Is(`[]byte`)",
Value: "b",
- Args: []ir.FilterExpr{{Line: 177, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 183, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
},
{
- Line: 179,
- SyntaxPatterns: []ir.PatternString{{Line: 179, Value: "len(string($b))"}},
+ Line: 185,
+ SyntaxPatterns: []ir.PatternString{{Line: 185, Value: "len(string($b))"}},
ReportTemplate: "suggestion: len($b)",
SuggestTemplate: "len($b)",
WhereExpr: ir.FilterExpr{
- Line: 179,
+ Line: 185,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"b\"].Type.Is(`[]byte`)",
Value: "b",
- Args: []ir.FilterExpr{{Line: 179, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 185, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
},
{
- Line: 181,
- SyntaxPatterns: []ir.PatternString{{Line: 181, Value: "string($x) == string($y)"}},
+ Line: 187,
+ SyntaxPatterns: []ir.PatternString{{Line: 187, Value: "string($x) == string($y)"}},
ReportTemplate: "suggestion: bytes.Equal($x, $y)",
SuggestTemplate: "bytes.Equal($x, $y)",
WhereExpr: ir.FilterExpr{
- Line: 182,
+ Line: 188,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Type.Is(`[]byte`) && m[\"y\"].Type.Is(`[]byte`)",
Args: []ir.FilterExpr{
{
- Line: 182,
+ Line: 188,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`[]byte`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 182, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 188, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
{
- Line: 182,
+ Line: 188,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"y\"].Type.Is(`[]byte`)",
Value: "y",
- Args: []ir.FilterExpr{{Line: 182, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 188, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
},
},
},
{
- Line: 185,
- SyntaxPatterns: []ir.PatternString{{Line: 185, Value: "string($x) != string($y)"}},
+ Line: 191,
+ SyntaxPatterns: []ir.PatternString{{Line: 191, Value: "string($x) != string($y)"}},
ReportTemplate: "suggestion: !bytes.Equal($x, $y)",
SuggestTemplate: "!bytes.Equal($x, $y)",
WhereExpr: ir.FilterExpr{
- Line: 186,
+ Line: 192,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Type.Is(`[]byte`) && m[\"y\"].Type.Is(`[]byte`)",
Args: []ir.FilterExpr{
{
- Line: 186,
+ Line: 192,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`[]byte`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 186, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 192, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
{
- Line: 186,
+ Line: 192,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"y\"].Type.Is(`[]byte`)",
Value: "y",
- Args: []ir.FilterExpr{{Line: 186, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
+ Args: []ir.FilterExpr{{Line: 192, Op: ir.FilterStringOp, Src: "`[]byte`", Value: "[]byte"}},
},
},
},
},
{
- Line: 189,
- SyntaxPatterns: []ir.PatternString{{Line: 189, Value: "$re.Match([]byte($s))"}},
+ Line: 195,
+ SyntaxPatterns: []ir.PatternString{{Line: 195, Value: "$re.Match([]byte($s))"}},
ReportTemplate: "suggestion: $re.MatchString($s)",
SuggestTemplate: "$re.MatchString($s)",
WhereExpr: ir.FilterExpr{
- Line: 190,
+ Line: 196,
Op: ir.FilterAndOp,
Src: "m[\"re\"].Type.Is(`*regexp.Regexp`) && m[\"s\"].Type.Is(`string`)",
Args: []ir.FilterExpr{
{
- Line: 190,
+ Line: 196,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"re\"].Type.Is(`*regexp.Regexp`)",
Value: "re",
- Args: []ir.FilterExpr{{Line: 190, Op: ir.FilterStringOp, Src: "`*regexp.Regexp`", Value: "*regexp.Regexp"}},
+ Args: []ir.FilterExpr{{Line: 196, Op: ir.FilterStringOp, Src: "`*regexp.Regexp`", Value: "*regexp.Regexp"}},
},
{
- Line: 190,
+ Line: 196,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`string`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 190, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 196, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
},
},
},
{
- Line: 193,
- SyntaxPatterns: []ir.PatternString{{Line: 193, Value: "$re.FindIndex([]byte($s))"}},
+ Line: 199,
+ SyntaxPatterns: []ir.PatternString{{Line: 199, Value: "$re.FindIndex([]byte($s))"}},
ReportTemplate: "suggestion: $re.FindStringIndex($s)",
SuggestTemplate: "$re.FindStringIndex($s)",
WhereExpr: ir.FilterExpr{
- Line: 194,
+ Line: 200,
Op: ir.FilterAndOp,
Src: "m[\"re\"].Type.Is(`*regexp.Regexp`) && m[\"s\"].Type.Is(`string`)",
Args: []ir.FilterExpr{
{
- Line: 194,
+ Line: 200,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"re\"].Type.Is(`*regexp.Regexp`)",
Value: "re",
- Args: []ir.FilterExpr{{Line: 194, Op: ir.FilterStringOp, Src: "`*regexp.Regexp`", Value: "*regexp.Regexp"}},
+ Args: []ir.FilterExpr{{Line: 200, Op: ir.FilterStringOp, Src: "`*regexp.Regexp`", Value: "*regexp.Regexp"}},
},
{
- Line: 194,
+ Line: 200,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`string`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 194, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 200, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
},
},
},
{
- Line: 197,
- SyntaxPatterns: []ir.PatternString{{Line: 197, Value: "$re.FindAllIndex([]byte($s), $n)"}},
+ Line: 203,
+ SyntaxPatterns: []ir.PatternString{{Line: 203, Value: "$re.FindAllIndex([]byte($s), $n)"}},
ReportTemplate: "suggestion: $re.FindAllStringIndex($s, $n)",
SuggestTemplate: "$re.FindAllStringIndex($s, $n)",
WhereExpr: ir.FilterExpr{
- Line: 198,
+ Line: 204,
Op: ir.FilterAndOp,
Src: "m[\"re\"].Type.Is(`*regexp.Regexp`) && m[\"s\"].Type.Is(`string`)",
Args: []ir.FilterExpr{
{
- Line: 198,
+ Line: 204,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"re\"].Type.Is(`*regexp.Regexp`)",
Value: "re",
- Args: []ir.FilterExpr{{Line: 198, Op: ir.FilterStringOp, Src: "`*regexp.Regexp`", Value: "*regexp.Regexp"}},
+ Args: []ir.FilterExpr{{Line: 204, Op: ir.FilterStringOp, Src: "`*regexp.Regexp`", Value: "*regexp.Regexp"}},
},
{
- Line: 198,
+ Line: 204,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`string`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 198, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 204, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
},
},
@@ -697,7 +721,7 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 207,
+ Line: 213,
Name: "indexAlloc",
MatcherName: "m",
DocTags: []string{"performance"},
@@ -706,22 +730,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: 208,
- SyntaxPatterns: []ir.PatternString{{Line: 208, Value: "strings.Index(string($x), $y)"}},
+ Line: 214,
+ SyntaxPatterns: []ir.PatternString{{Line: 214, Value: "strings.Index(string($x), $y)"}},
ReportTemplate: "consider replacing $$ with bytes.Index($x, []byte($y))",
WhereExpr: ir.FilterExpr{
- Line: 209,
+ Line: 215,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure",
Args: []ir.FilterExpr{
- {Line: 209, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
- {Line: 209, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
+ {Line: 215, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ {Line: 215, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
},
},
}},
},
{
- Line: 217,
+ Line: 223,
Name: "wrapperFunc",
MatcherName: "m",
DocTags: []string{"style"},
@@ -730,169 +754,169 @@ var PrecompiledRules = &ir.File{
DocAfter: "wg.Done()",
Rules: []ir.Rule{
{
- Line: 218,
- SyntaxPatterns: []ir.PatternString{{Line: 218, Value: "$wg.Add(-1)"}},
+ Line: 224,
+ SyntaxPatterns: []ir.PatternString{{Line: 224, Value: "$wg.Add(-1)"}},
ReportTemplate: "use WaitGroup.Done method in `$$`",
WhereExpr: ir.FilterExpr{
- Line: 219,
+ Line: 225,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"wg\"].Type.Is(`sync.WaitGroup`)",
Value: "wg",
- Args: []ir.FilterExpr{{Line: 219, Op: ir.FilterStringOp, Src: "`sync.WaitGroup`", Value: "sync.WaitGroup"}},
+ Args: []ir.FilterExpr{{Line: 225, Op: ir.FilterStringOp, Src: "`sync.WaitGroup`", Value: "sync.WaitGroup"}},
},
},
{
- Line: 222,
- SyntaxPatterns: []ir.PatternString{{Line: 222, Value: "$buf.Truncate(0)"}},
+ Line: 228,
+ SyntaxPatterns: []ir.PatternString{{Line: 228, Value: "$buf.Truncate(0)"}},
ReportTemplate: "use Buffer.Reset method in `$$`",
WhereExpr: ir.FilterExpr{
- Line: 223,
+ Line: 229,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"buf\"].Type.Is(`bytes.Buffer`)",
Value: "buf",
- Args: []ir.FilterExpr{{Line: 223, Op: ir.FilterStringOp, Src: "`bytes.Buffer`", Value: "bytes.Buffer"}},
+ Args: []ir.FilterExpr{{Line: 229, Op: ir.FilterStringOp, Src: "`bytes.Buffer`", Value: "bytes.Buffer"}},
},
},
{
- Line: 226,
- SyntaxPatterns: []ir.PatternString{{Line: 226, Value: "http.HandlerFunc(http.NotFound)"}},
+ Line: 232,
+ SyntaxPatterns: []ir.PatternString{{Line: 232, Value: "http.HandlerFunc(http.NotFound)"}},
ReportTemplate: "use http.NotFoundHandler method in `$$`",
},
{
- Line: 228,
- SyntaxPatterns: []ir.PatternString{{Line: 228, Value: "strings.SplitN($_, $_, -1)"}},
+ Line: 234,
+ SyntaxPatterns: []ir.PatternString{{Line: 234, Value: "strings.SplitN($_, $_, -1)"}},
ReportTemplate: "use strings.Split method in `$$`",
},
{
- Line: 229,
- SyntaxPatterns: []ir.PatternString{{Line: 229, Value: "strings.Replace($_, $_, $_, -1)"}},
+ Line: 235,
+ SyntaxPatterns: []ir.PatternString{{Line: 235, Value: "strings.Replace($_, $_, $_, -1)"}},
ReportTemplate: "use strings.ReplaceAll method in `$$`",
},
{
- Line: 230,
- SyntaxPatterns: []ir.PatternString{{Line: 230, Value: "strings.Map(unicode.ToTitle, $_)"}},
+ Line: 236,
+ SyntaxPatterns: []ir.PatternString{{Line: 236, Value: "strings.Map(unicode.ToTitle, $_)"}},
ReportTemplate: "use strings.ToTitle method in `$$`",
},
{
- Line: 231,
+ Line: 237,
SyntaxPatterns: []ir.PatternString{
- {Line: 231, Value: "strings.Index($s1, $s2) >= 0"},
- {Line: 231, Value: "strings.Index($s1, $s2) != -1"},
+ {Line: 237, Value: "strings.Index($s1, $s2) >= 0"},
+ {Line: 237, Value: "strings.Index($s1, $s2) != -1"},
},
ReportTemplate: "suggestion: strings.Contains($s1, $s2)",
SuggestTemplate: "strings.Contains($s1, $s2)",
},
{
- Line: 232,
+ Line: 238,
SyntaxPatterns: []ir.PatternString{
- {Line: 232, Value: "strings.IndexAny($s1, $s2) >= 0"},
- {Line: 232, Value: "strings.IndexAny($s1, $s2) != -1"},
+ {Line: 238, Value: "strings.IndexAny($s1, $s2) >= 0"},
+ {Line: 238, Value: "strings.IndexAny($s1, $s2) != -1"},
},
ReportTemplate: "suggestion: strings.ContainsAny($s1, $s2)",
SuggestTemplate: "strings.ContainsAny($s1, $s2)",
},
{
- Line: 233,
+ Line: 239,
SyntaxPatterns: []ir.PatternString{
- {Line: 233, Value: "strings.IndexRune($s1, $s2) >= 0"},
- {Line: 233, Value: "strings.IndexRune($s1, $s2) != -1"},
+ {Line: 239, Value: "strings.IndexRune($s1, $s2) >= 0"},
+ {Line: 239, Value: "strings.IndexRune($s1, $s2) != -1"},
},
ReportTemplate: "suggestion: strings.ContainsRune($s1, $s2)",
SuggestTemplate: "strings.ContainsRune($s1, $s2)",
},
{
- Line: 235,
+ Line: 241,
SyntaxPatterns: []ir.PatternString{
- {Line: 235, Value: "$i := strings.Index($s, $sep); $*_; $x, $y = $s[:$i], $s[$i+1:]"},
- {Line: 236, Value: "$i := strings.Index($s, $sep); $*_; $x = $s[:$i]; $*_; $y = $s[$i+1:]"},
+ {Line: 241, Value: "$i := strings.Index($s, $sep); $*_; $x, $y = $s[:$i], $s[$i+1:]"},
+ {Line: 242, Value: "$i := strings.Index($s, $sep); $*_; $x = $s[:$i]; $*_; $y = $s[$i+1:]"},
},
ReportTemplate: "suggestion: $x, $y, _ = strings.Cut($s, $sep)",
SuggestTemplate: "$x, $y, _ = strings.Cut($s, $sep)",
WhereExpr: ir.FilterExpr{
- Line: 237,
+ Line: 243,
Op: ir.FilterGoVersionGreaterEqThanOp,
Src: "m.GoVersion().GreaterEqThan(\"1.18\")",
Value: "1.18",
},
},
{
- Line: 240,
+ Line: 246,
SyntaxPatterns: []ir.PatternString{
- {Line: 241, Value: "if $i := strings.Index($s, $sep); $i != -1 { $*_; $x, $y = $s[:$i], $s[$i+1:]; $*_ }"},
- {Line: 242, Value: "if $i := strings.Index($s, $sep); $i != -1 { $*_; $x = $s[:$i]; $*_; $y = $s[$i+1:]; $*_ }"},
- {Line: 243, Value: "if $i := strings.Index($s, $sep); $i >= 0 { $*_; $x, $y = $s[:$i], $s[$i+1:]; $*_ }"},
- {Line: 244, Value: "if $i := strings.Index($s, $sep); $i >= 0 { $*_; $x = $s[:$i]; $*_; $y = $s[$i+1:]; $*_ }"},
+ {Line: 247, Value: "if $i := strings.Index($s, $sep); $i != -1 { $*_; $x, $y = $s[:$i], $s[$i+1:]; $*_ }"},
+ {Line: 248, Value: "if $i := strings.Index($s, $sep); $i != -1 { $*_; $x = $s[:$i]; $*_; $y = $s[$i+1:]; $*_ }"},
+ {Line: 249, Value: "if $i := strings.Index($s, $sep); $i >= 0 { $*_; $x, $y = $s[:$i], $s[$i+1:]; $*_ }"},
+ {Line: 250, Value: "if $i := strings.Index($s, $sep); $i >= 0 { $*_; $x = $s[:$i]; $*_; $y = $s[$i+1:]; $*_ }"},
},
ReportTemplate: "suggestion: if $x, $y, ok = strings.Cut($s, $sep); ok { ... }",
SuggestTemplate: "if $x, $y, ok = strings.Cut($s, $sep); ok { ... }",
WhereExpr: ir.FilterExpr{
- Line: 245,
+ Line: 251,
Op: ir.FilterGoVersionGreaterEqThanOp,
Src: "m.GoVersion().GreaterEqThan(\"1.18\")",
Value: "1.18",
},
},
{
- Line: 248,
- SyntaxPatterns: []ir.PatternString{{Line: 248, Value: "bytes.SplitN(b, []byte(\".\"), -1)"}},
+ Line: 254,
+ SyntaxPatterns: []ir.PatternString{{Line: 254, Value: "bytes.SplitN(b, []byte(\".\"), -1)"}},
ReportTemplate: "use bytes.Split method in `$$`",
},
{
- Line: 249,
- SyntaxPatterns: []ir.PatternString{{Line: 249, Value: "bytes.Replace($_, $_, $_, -1)"}},
+ Line: 255,
+ SyntaxPatterns: []ir.PatternString{{Line: 255, Value: "bytes.Replace($_, $_, $_, -1)"}},
ReportTemplate: "use bytes.ReplaceAll method in `$$`",
},
{
- Line: 250,
- SyntaxPatterns: []ir.PatternString{{Line: 250, Value: "bytes.Map(unicode.ToUpper, $_)"}},
+ Line: 256,
+ SyntaxPatterns: []ir.PatternString{{Line: 256, Value: "bytes.Map(unicode.ToUpper, $_)"}},
ReportTemplate: "use bytes.ToUpper method in `$$`",
},
{
- Line: 251,
- SyntaxPatterns: []ir.PatternString{{Line: 251, Value: "bytes.Map(unicode.ToLower, $_)"}},
+ Line: 257,
+ SyntaxPatterns: []ir.PatternString{{Line: 257, Value: "bytes.Map(unicode.ToLower, $_)"}},
ReportTemplate: "use bytes.ToLower method in `$$`",
},
{
- Line: 252,
- SyntaxPatterns: []ir.PatternString{{Line: 252, Value: "bytes.Map(unicode.ToTitle, $_)"}},
+ Line: 258,
+ SyntaxPatterns: []ir.PatternString{{Line: 258, Value: "bytes.Map(unicode.ToTitle, $_)"}},
ReportTemplate: "use bytes.ToTitle method in `$$`",
},
{
- Line: 253,
+ Line: 259,
SyntaxPatterns: []ir.PatternString{
- {Line: 253, Value: "bytes.Index($b1, $b2) >= 0"},
- {Line: 253, Value: "bytes.Index($b1, $b2) != -1"},
+ {Line: 259, Value: "bytes.Index($b1, $b2) >= 0"},
+ {Line: 259, Value: "bytes.Index($b1, $b2) != -1"},
},
ReportTemplate: "suggestion: bytes.Contains($b1, $b2)",
SuggestTemplate: "bytes.Contains($b1, $b2)",
},
{
- Line: 254,
+ Line: 260,
SyntaxPatterns: []ir.PatternString{
- {Line: 254, Value: "bytes.IndexAny($b1, $b2) >= 0"},
- {Line: 254, Value: "bytes.IndexAny($b1, $b2) != -1"},
+ {Line: 260, Value: "bytes.IndexAny($b1, $b2) >= 0"},
+ {Line: 260, Value: "bytes.IndexAny($b1, $b2) != -1"},
},
ReportTemplate: "suggestion: bytes.ContainsAny($b1, $b2)",
SuggestTemplate: "bytes.ContainsAny($b1, $b2)",
},
{
- Line: 255,
+ Line: 261,
SyntaxPatterns: []ir.PatternString{
- {Line: 255, Value: "bytes.IndexRune($b1, $b2) >= 0"},
- {Line: 255, Value: "bytes.IndexRune($b1, $b2) != -1"},
+ {Line: 261, Value: "bytes.IndexRune($b1, $b2) >= 0"},
+ {Line: 261, Value: "bytes.IndexRune($b1, $b2) != -1"},
},
ReportTemplate: "suggestion: bytes.ContainsRune($b1, $b2)",
SuggestTemplate: "bytes.ContainsRune($b1, $b2)",
},
{
- Line: 257,
- SyntaxPatterns: []ir.PatternString{{Line: 257, Value: "draw.DrawMask($_, $_, $_, $_, nil, image.Point{}, $_)"}},
+ Line: 263,
+ SyntaxPatterns: []ir.PatternString{{Line: 263, Value: "draw.DrawMask($_, $_, $_, $_, nil, image.Point{}, $_)"}},
ReportTemplate: "use draw.Draw method in `$$`",
},
},
},
{
- Line: 265,
+ Line: 271,
Name: "regexpMust",
MatcherName: "m",
DocTags: []string{"style"},
@@ -901,22 +925,22 @@ var PrecompiledRules = &ir.File{
DocAfter: "re := regexp.MustCompile(\"const pattern\")",
Rules: []ir.Rule{
{
- Line: 266,
- SyntaxPatterns: []ir.PatternString{{Line: 266, Value: "regexp.Compile($pat)"}},
+ Line: 272,
+ SyntaxPatterns: []ir.PatternString{{Line: 272, Value: "regexp.Compile($pat)"}},
ReportTemplate: "for const patterns like $pat, use regexp.MustCompile",
WhereExpr: ir.FilterExpr{
- Line: 267,
+ Line: 273,
Op: ir.FilterVarConstOp,
Src: "m[\"pat\"].Const",
Value: "pat",
},
},
{
- Line: 270,
- SyntaxPatterns: []ir.PatternString{{Line: 270, Value: "regexp.CompilePOSIX($pat)"}},
+ Line: 276,
+ SyntaxPatterns: []ir.PatternString{{Line: 276, Value: "regexp.CompilePOSIX($pat)"}},
ReportTemplate: "for const patterns like $pat, use regexp.MustCompilePOSIX",
WhereExpr: ir.FilterExpr{
- Line: 271,
+ Line: 277,
Op: ir.FilterVarConstOp,
Src: "m[\"pat\"].Const",
Value: "pat",
@@ -925,7 +949,7 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 279,
+ Line: 285,
Name: "badCall",
MatcherName: "m",
DocTags: []string{"diagnostic"},
@@ -934,22 +958,22 @@ var PrecompiledRules = &ir.File{
DocAfter: "strings.Replace(s, from, to, -1)",
Rules: []ir.Rule{
{
- Line: 280,
- SyntaxPatterns: []ir.PatternString{{Line: 280, Value: "strings.Replace($_, $_, $_, $zero)"}},
+ Line: 286,
+ SyntaxPatterns: []ir.PatternString{{Line: 286, Value: "strings.Replace($_, $_, $_, $zero)"}},
ReportTemplate: "suspicious arg 0, probably meant -1",
WhereExpr: ir.FilterExpr{
- Line: 281,
+ Line: 287,
Op: ir.FilterEqOp,
Src: "m[\"zero\"].Value.Int() == 0",
Args: []ir.FilterExpr{
{
- Line: 281,
+ Line: 287,
Op: ir.FilterVarValueIntOp,
Src: "m[\"zero\"].Value.Int()",
Value: "zero",
},
{
- Line: 281,
+ Line: 287,
Op: ir.FilterIntOp,
Src: "0",
Value: int64(0),
@@ -959,22 +983,22 @@ var PrecompiledRules = &ir.File{
LocationVar: "zero",
},
{
- Line: 283,
- SyntaxPatterns: []ir.PatternString{{Line: 283, Value: "bytes.Replace($_, $_, $_, $zero)"}},
+ Line: 289,
+ SyntaxPatterns: []ir.PatternString{{Line: 289, Value: "bytes.Replace($_, $_, $_, $zero)"}},
ReportTemplate: "suspicious arg 0, probably meant -1",
WhereExpr: ir.FilterExpr{
- Line: 284,
+ Line: 290,
Op: ir.FilterEqOp,
Src: "m[\"zero\"].Value.Int() == 0",
Args: []ir.FilterExpr{
{
- Line: 284,
+ Line: 290,
Op: ir.FilterVarValueIntOp,
Src: "m[\"zero\"].Value.Int()",
Value: "zero",
},
{
- Line: 284,
+ Line: 290,
Op: ir.FilterIntOp,
Src: "0",
Value: int64(0),
@@ -984,22 +1008,22 @@ var PrecompiledRules = &ir.File{
LocationVar: "zero",
},
{
- Line: 287,
- SyntaxPatterns: []ir.PatternString{{Line: 287, Value: "strings.SplitN($_, $_, $zero)"}},
+ Line: 293,
+ SyntaxPatterns: []ir.PatternString{{Line: 293, Value: "strings.SplitN($_, $_, $zero)"}},
ReportTemplate: "suspicious arg 0, probably meant -1",
WhereExpr: ir.FilterExpr{
- Line: 288,
+ Line: 294,
Op: ir.FilterEqOp,
Src: "m[\"zero\"].Value.Int() == 0",
Args: []ir.FilterExpr{
{
- Line: 288,
+ Line: 294,
Op: ir.FilterVarValueIntOp,
Src: "m[\"zero\"].Value.Int()",
Value: "zero",
},
{
- Line: 288,
+ Line: 294,
Op: ir.FilterIntOp,
Src: "0",
Value: int64(0),
@@ -1009,22 +1033,22 @@ var PrecompiledRules = &ir.File{
LocationVar: "zero",
},
{
- Line: 290,
- SyntaxPatterns: []ir.PatternString{{Line: 290, Value: "bytes.SplitN($_, $_, $zero)"}},
+ Line: 296,
+ SyntaxPatterns: []ir.PatternString{{Line: 296, Value: "bytes.SplitN($_, $_, $zero)"}},
ReportTemplate: "suspicious arg 0, probably meant -1",
WhereExpr: ir.FilterExpr{
- Line: 291,
+ Line: 297,
Op: ir.FilterEqOp,
Src: "m[\"zero\"].Value.Int() == 0",
Args: []ir.FilterExpr{
{
- Line: 291,
+ Line: 297,
Op: ir.FilterVarValueIntOp,
Src: "m[\"zero\"].Value.Int()",
Value: "zero",
},
{
- Line: 291,
+ Line: 297,
Op: ir.FilterIntOp,
Src: "0",
Value: int64(0),
@@ -1034,19 +1058,19 @@ var PrecompiledRules = &ir.File{
LocationVar: "zero",
},
{
- Line: 294,
- SyntaxPatterns: []ir.PatternString{{Line: 294, Value: "append($_)"}},
+ Line: 300,
+ SyntaxPatterns: []ir.PatternString{{Line: 300, Value: "append($_)"}},
ReportTemplate: "no-op append call, probably missing arguments",
},
{
- Line: 296,
- SyntaxPatterns: []ir.PatternString{{Line: 296, Value: "filepath.Join($_)"}},
+ Line: 302,
+ SyntaxPatterns: []ir.PatternString{{Line: 302, Value: "filepath.Join($_)"}},
ReportTemplate: "suspicious Join on 1 argument",
},
},
},
{
- Line: 303,
+ Line: 309,
Name: "assignOp",
MatcherName: "m",
DocTags: []string{"style"},
@@ -1055,87 +1079,87 @@ var PrecompiledRules = &ir.File{
DocAfter: "x *= 2",
Rules: []ir.Rule{
{
- Line: 304,
- SyntaxPatterns: []ir.PatternString{{Line: 304, Value: "$x = $x + 1"}},
+ Line: 310,
+ SyntaxPatterns: []ir.PatternString{{Line: 310, Value: "$x = $x + 1"}},
ReportTemplate: "replace `$$` with `$x++`",
- WhereExpr: ir.FilterExpr{Line: 304, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 310, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 305,
- SyntaxPatterns: []ir.PatternString{{Line: 305, Value: "$x = $x - 1"}},
+ Line: 311,
+ SyntaxPatterns: []ir.PatternString{{Line: 311, Value: "$x = $x - 1"}},
ReportTemplate: "replace `$$` with `$x--`",
- WhereExpr: ir.FilterExpr{Line: 305, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 311, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 307,
- SyntaxPatterns: []ir.PatternString{{Line: 307, Value: "$x = $x + $y"}},
+ Line: 313,
+ SyntaxPatterns: []ir.PatternString{{Line: 313, Value: "$x = $x + $y"}},
ReportTemplate: "replace `$$` with `$x += $y`",
- WhereExpr: ir.FilterExpr{Line: 307, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 313, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 308,
- SyntaxPatterns: []ir.PatternString{{Line: 308, Value: "$x = $x - $y"}},
+ Line: 314,
+ SyntaxPatterns: []ir.PatternString{{Line: 314, Value: "$x = $x - $y"}},
ReportTemplate: "replace `$$` with `$x -= $y`",
- WhereExpr: ir.FilterExpr{Line: 308, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 314, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 310,
- SyntaxPatterns: []ir.PatternString{{Line: 310, Value: "$x = $x * $y"}},
+ Line: 316,
+ SyntaxPatterns: []ir.PatternString{{Line: 316, Value: "$x = $x * $y"}},
ReportTemplate: "replace `$$` with `$x *= $y`",
- WhereExpr: ir.FilterExpr{Line: 310, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 316, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 311,
- SyntaxPatterns: []ir.PatternString{{Line: 311, Value: "$x = $x / $y"}},
+ Line: 317,
+ SyntaxPatterns: []ir.PatternString{{Line: 317, Value: "$x = $x / $y"}},
ReportTemplate: "replace `$$` with `$x /= $y`",
- WhereExpr: ir.FilterExpr{Line: 311, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 317, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 312,
- SyntaxPatterns: []ir.PatternString{{Line: 312, Value: "$x = $x % $y"}},
+ Line: 318,
+ SyntaxPatterns: []ir.PatternString{{Line: 318, Value: "$x = $x % $y"}},
ReportTemplate: "replace `$$` with `$x %= $y`",
- WhereExpr: ir.FilterExpr{Line: 312, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 318, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 313,
- SyntaxPatterns: []ir.PatternString{{Line: 313, Value: "$x = $x & $y"}},
+ Line: 319,
+ SyntaxPatterns: []ir.PatternString{{Line: 319, Value: "$x = $x & $y"}},
ReportTemplate: "replace `$$` with `$x &= $y`",
- WhereExpr: ir.FilterExpr{Line: 313, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 319, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 314,
- SyntaxPatterns: []ir.PatternString{{Line: 314, Value: "$x = $x | $y"}},
+ Line: 320,
+ SyntaxPatterns: []ir.PatternString{{Line: 320, Value: "$x = $x | $y"}},
ReportTemplate: "replace `$$` with `$x |= $y`",
- WhereExpr: ir.FilterExpr{Line: 314, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 320, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 315,
- SyntaxPatterns: []ir.PatternString{{Line: 315, Value: "$x = $x ^ $y"}},
+ Line: 321,
+ SyntaxPatterns: []ir.PatternString{{Line: 321, Value: "$x = $x ^ $y"}},
ReportTemplate: "replace `$$` with `$x ^= $y`",
- WhereExpr: ir.FilterExpr{Line: 315, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 321, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 316,
- SyntaxPatterns: []ir.PatternString{{Line: 316, Value: "$x = $x << $y"}},
+ Line: 322,
+ SyntaxPatterns: []ir.PatternString{{Line: 322, Value: "$x = $x << $y"}},
ReportTemplate: "replace `$$` with `$x <<= $y`",
- WhereExpr: ir.FilterExpr{Line: 316, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 322, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 317,
- SyntaxPatterns: []ir.PatternString{{Line: 317, Value: "$x = $x >> $y"}},
+ Line: 323,
+ SyntaxPatterns: []ir.PatternString{{Line: 323, Value: "$x = $x >> $y"}},
ReportTemplate: "replace `$$` with `$x >>= $y`",
- WhereExpr: ir.FilterExpr{Line: 317, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 323, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 318,
- SyntaxPatterns: []ir.PatternString{{Line: 318, Value: "$x = $x &^ $y"}},
+ Line: 324,
+ SyntaxPatterns: []ir.PatternString{{Line: 324, Value: "$x = $x &^ $y"}},
ReportTemplate: "replace `$$` with `$x &^= $y`",
- WhereExpr: ir.FilterExpr{Line: 318, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 324, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
},
},
{
- Line: 325,
+ Line: 331,
Name: "preferWriteByte",
MatcherName: "m",
DocTags: []string{"performance", "experimental", "opinionated"},
@@ -1143,45 +1167,45 @@ var PrecompiledRules = &ir.File{
DocBefore: "w.WriteRune('\\n')",
DocAfter: "w.WriteByte('\\n')",
Rules: []ir.Rule{{
- Line: 329,
- SyntaxPatterns: []ir.PatternString{{Line: 329, Value: "$w.WriteRune($c)"}},
+ Line: 335,
+ SyntaxPatterns: []ir.PatternString{{Line: 335, Value: "$w.WriteRune($c)"}},
ReportTemplate: "consider writing single byte rune $c with $w.WriteByte($c)",
WhereExpr: ir.FilterExpr{
- Line: 330,
+ Line: 336,
Op: ir.FilterAndOp,
Src: "m[\"w\"].Type.Implements(\"io.ByteWriter\") && (m[\"c\"].Const && m[\"c\"].Value.Int() < runeSelf)",
Args: []ir.FilterExpr{
{
- Line: 330,
+ Line: 336,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.ByteWriter\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 330, Op: ir.FilterStringOp, Src: "\"io.ByteWriter\"", Value: "io.ByteWriter"}},
+ Args: []ir.FilterExpr{{Line: 336, Op: ir.FilterStringOp, Src: "\"io.ByteWriter\"", Value: "io.ByteWriter"}},
},
{
- Line: 330,
+ Line: 336,
Op: ir.FilterAndOp,
Src: "(m[\"c\"].Const && m[\"c\"].Value.Int() < runeSelf)",
Args: []ir.FilterExpr{
{
- Line: 330,
+ Line: 336,
Op: ir.FilterVarConstOp,
Src: "m[\"c\"].Const",
Value: "c",
},
{
- Line: 330,
+ Line: 336,
Op: ir.FilterLtOp,
Src: "m[\"c\"].Value.Int() < runeSelf",
Args: []ir.FilterExpr{
{
- Line: 330,
+ Line: 336,
Op: ir.FilterVarValueIntOp,
Src: "m[\"c\"].Value.Int()",
Value: "c",
},
{
- Line: 330,
+ Line: 336,
Op: ir.FilterIntOp,
Src: "runeSelf",
Value: int64(128),
@@ -1195,7 +1219,7 @@ var PrecompiledRules = &ir.File{
}},
},
{
- Line: 338,
+ Line: 344,
Name: "preferFprint",
MatcherName: "m",
DocTags: []string{"performance", "experimental"},
@@ -1204,139 +1228,139 @@ var PrecompiledRules = &ir.File{
DocAfter: "fmt.Fprintf(w, \"%x\", 10)",
Rules: []ir.Rule{
{
- Line: 339,
- SyntaxPatterns: []ir.PatternString{{Line: 339, Value: "$w.Write([]byte(fmt.Sprint($*args)))"}},
+ Line: 345,
+ SyntaxPatterns: []ir.PatternString{{Line: 345, 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: 340,
+ Line: 346,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.Writer\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 340, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
+ Args: []ir.FilterExpr{{Line: 346, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
},
},
{
- Line: 344,
- SyntaxPatterns: []ir.PatternString{{Line: 344, Value: "$w.Write([]byte(fmt.Sprintf($*args)))"}},
+ Line: 350,
+ SyntaxPatterns: []ir.PatternString{{Line: 350, 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: 345,
+ Line: 351,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.Writer\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 345, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
+ Args: []ir.FilterExpr{{Line: 351, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
},
},
{
- Line: 349,
- SyntaxPatterns: []ir.PatternString{{Line: 349, Value: "$w.Write([]byte(fmt.Sprintln($*args)))"}},
+ Line: 355,
+ SyntaxPatterns: []ir.PatternString{{Line: 355, 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: 350,
+ Line: 356,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.Writer\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 350, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
+ Args: []ir.FilterExpr{{Line: 356, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
},
},
{
- Line: 354,
- SyntaxPatterns: []ir.PatternString{{Line: 354, Value: "io.WriteString($w, fmt.Sprint($*args))"}},
+ Line: 360,
+ SyntaxPatterns: []ir.PatternString{{Line: 360, Value: "io.WriteString($w, fmt.Sprint($*args))"}},
ReportTemplate: "suggestion: fmt.Fprint($w, $args)",
SuggestTemplate: "fmt.Fprint($w, $args)",
},
{
- Line: 355,
- SyntaxPatterns: []ir.PatternString{{Line: 355, Value: "io.WriteString($w, fmt.Sprintf($*args))"}},
+ Line: 361,
+ SyntaxPatterns: []ir.PatternString{{Line: 361, Value: "io.WriteString($w, fmt.Sprintf($*args))"}},
ReportTemplate: "suggestion: fmt.Fprintf($w, $args)",
SuggestTemplate: "fmt.Fprintf($w, $args)",
},
{
- Line: 356,
- SyntaxPatterns: []ir.PatternString{{Line: 356, Value: "io.WriteString($w, fmt.Sprintln($*args))"}},
+ Line: 362,
+ SyntaxPatterns: []ir.PatternString{{Line: 362, Value: "io.WriteString($w, fmt.Sprintln($*args))"}},
ReportTemplate: "suggestion: fmt.Fprintln($w, $args)",
SuggestTemplate: "fmt.Fprintln($w, $args)",
},
{
- Line: 358,
- SyntaxPatterns: []ir.PatternString{{Line: 358, Value: "$w.WriteString(fmt.Sprint($*args))"}},
+ Line: 364,
+ SyntaxPatterns: []ir.PatternString{{Line: 364, Value: "$w.WriteString(fmt.Sprint($*args))"}},
ReportTemplate: "suggestion: fmt.Fprint($w, $args)",
SuggestTemplate: "fmt.Fprint($w, $args)",
WhereExpr: ir.FilterExpr{
- Line: 359,
+ Line: 365,
Op: ir.FilterAndOp,
Src: "m[\"w\"].Type.Implements(\"io.Writer\") && m[\"w\"].Type.Implements(\"io.StringWriter\")",
Args: []ir.FilterExpr{
{
- Line: 359,
+ Line: 365,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.Writer\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 359, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
+ Args: []ir.FilterExpr{{Line: 365, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
},
{
- Line: 359,
+ Line: 365,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.StringWriter\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 359, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
+ Args: []ir.FilterExpr{{Line: 365, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
},
},
},
},
{
- Line: 361,
- SyntaxPatterns: []ir.PatternString{{Line: 361, Value: "$w.WriteString(fmt.Sprintf($*args))"}},
+ Line: 367,
+ SyntaxPatterns: []ir.PatternString{{Line: 367, Value: "$w.WriteString(fmt.Sprintf($*args))"}},
ReportTemplate: "suggestion: fmt.Fprintf($w, $args)",
SuggestTemplate: "fmt.Fprintf($w, $args)",
WhereExpr: ir.FilterExpr{
- Line: 362,
+ Line: 368,
Op: ir.FilterAndOp,
Src: "m[\"w\"].Type.Implements(\"io.Writer\") && m[\"w\"].Type.Implements(\"io.StringWriter\")",
Args: []ir.FilterExpr{
{
- Line: 362,
+ Line: 368,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.Writer\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 362, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
+ Args: []ir.FilterExpr{{Line: 368, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
},
{
- Line: 362,
+ Line: 368,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.StringWriter\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 362, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
+ Args: []ir.FilterExpr{{Line: 368, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
},
},
},
},
{
- Line: 364,
- SyntaxPatterns: []ir.PatternString{{Line: 364, Value: "$w.WriteString(fmt.Sprintln($*args))"}},
+ Line: 370,
+ SyntaxPatterns: []ir.PatternString{{Line: 370, Value: "$w.WriteString(fmt.Sprintln($*args))"}},
ReportTemplate: "suggestion: fmt.Fprintln($w, $args)",
SuggestTemplate: "fmt.Fprintln($w, $args)",
WhereExpr: ir.FilterExpr{
- Line: 365,
+ Line: 371,
Op: ir.FilterAndOp,
Src: "m[\"w\"].Type.Implements(\"io.Writer\") && m[\"w\"].Type.Implements(\"io.StringWriter\")",
Args: []ir.FilterExpr{
{
- Line: 365,
+ Line: 371,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.Writer\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 365, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
+ Args: []ir.FilterExpr{{Line: 371, Op: ir.FilterStringOp, Src: "\"io.Writer\"", Value: "io.Writer"}},
},
{
- Line: 365,
+ Line: 371,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.StringWriter\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 365, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
+ Args: []ir.FilterExpr{{Line: 371, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
},
},
},
@@ -1344,7 +1368,7 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 373,
+ Line: 379,
Name: "dupArg",
MatcherName: "m",
DocTags: []string{"diagnostic"},
@@ -1353,62 +1377,62 @@ var PrecompiledRules = &ir.File{
DocAfter: "copy(dst, src)",
Rules: []ir.Rule{
{
- Line: 374,
+ Line: 380,
SyntaxPatterns: []ir.PatternString{
- {Line: 374, Value: "$x.Equal($x)"},
- {Line: 374, Value: "$x.Equals($x)"},
- {Line: 374, Value: "$x.Compare($x)"},
- {Line: 374, Value: "$x.Cmp($x)"},
+ {Line: 380, Value: "$x.Equal($x)"},
+ {Line: 380, Value: "$x.Equals($x)"},
+ {Line: 380, Value: "$x.Compare($x)"},
+ {Line: 380, Value: "$x.Cmp($x)"},
},
ReportTemplate: "suspicious method call with the same argument and receiver",
- WhereExpr: ir.FilterExpr{Line: 375, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 381, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
{
- Line: 378,
+ Line: 384,
SyntaxPatterns: []ir.PatternString{
- {Line: 378, Value: "copy($x, $x)"},
- {Line: 379, Value: "math.Max($x, $x)"},
- {Line: 380, Value: "math.Min($x, $x)"},
- {Line: 381, Value: "reflect.Copy($x, $x)"},
- {Line: 382, Value: "reflect.DeepEqual($x, $x)"},
- {Line: 383, Value: "strings.Contains($x, $x)"},
- {Line: 384, Value: "strings.Compare($x, $x)"},
- {Line: 385, Value: "strings.EqualFold($x, $x)"},
- {Line: 386, Value: "strings.HasPrefix($x, $x)"},
- {Line: 387, Value: "strings.HasSuffix($x, $x)"},
- {Line: 388, Value: "strings.Index($x, $x)"},
- {Line: 389, Value: "strings.LastIndex($x, $x)"},
- {Line: 390, Value: "strings.Split($x, $x)"},
- {Line: 391, Value: "strings.SplitAfter($x, $x)"},
- {Line: 392, Value: "strings.SplitAfterN($x, $x, $_)"},
- {Line: 393, Value: "strings.SplitN($x, $x, $_)"},
- {Line: 394, Value: "strings.Replace($_, $x, $x, $_)"},
- {Line: 395, Value: "strings.ReplaceAll($_, $x, $x)"},
- {Line: 396, Value: "bytes.Contains($x, $x)"},
- {Line: 397, Value: "bytes.Compare($x, $x)"},
- {Line: 398, Value: "bytes.Equal($x, $x)"},
- {Line: 399, Value: "bytes.EqualFold($x, $x)"},
- {Line: 400, Value: "bytes.HasPrefix($x, $x)"},
- {Line: 401, Value: "bytes.HasSuffix($x, $x)"},
- {Line: 402, Value: "bytes.Index($x, $x)"},
- {Line: 403, Value: "bytes.LastIndex($x, $x)"},
- {Line: 404, Value: "bytes.Split($x, $x)"},
- {Line: 405, Value: "bytes.SplitAfter($x, $x)"},
- {Line: 406, Value: "bytes.SplitAfterN($x, $x, $_)"},
- {Line: 407, Value: "bytes.SplitN($x, $x, $_)"},
- {Line: 408, Value: "bytes.Replace($_, $x, $x, $_)"},
- {Line: 409, Value: "bytes.ReplaceAll($_, $x, $x)"},
- {Line: 410, Value: "types.Identical($x, $x)"},
- {Line: 411, Value: "types.IdenticalIgnoreTags($x, $x)"},
- {Line: 412, Value: "draw.Draw($x, $_, $x, $_, $_)"},
+ {Line: 384, Value: "copy($x, $x)"},
+ {Line: 385, Value: "math.Max($x, $x)"},
+ {Line: 386, Value: "math.Min($x, $x)"},
+ {Line: 387, Value: "reflect.Copy($x, $x)"},
+ {Line: 388, Value: "reflect.DeepEqual($x, $x)"},
+ {Line: 389, Value: "strings.Contains($x, $x)"},
+ {Line: 390, Value: "strings.Compare($x, $x)"},
+ {Line: 391, Value: "strings.EqualFold($x, $x)"},
+ {Line: 392, Value: "strings.HasPrefix($x, $x)"},
+ {Line: 393, Value: "strings.HasSuffix($x, $x)"},
+ {Line: 394, Value: "strings.Index($x, $x)"},
+ {Line: 395, Value: "strings.LastIndex($x, $x)"},
+ {Line: 396, Value: "strings.Split($x, $x)"},
+ {Line: 397, Value: "strings.SplitAfter($x, $x)"},
+ {Line: 398, Value: "strings.SplitAfterN($x, $x, $_)"},
+ {Line: 399, Value: "strings.SplitN($x, $x, $_)"},
+ {Line: 400, Value: "strings.Replace($_, $x, $x, $_)"},
+ {Line: 401, Value: "strings.ReplaceAll($_, $x, $x)"},
+ {Line: 402, Value: "bytes.Contains($x, $x)"},
+ {Line: 403, Value: "bytes.Compare($x, $x)"},
+ {Line: 404, Value: "bytes.Equal($x, $x)"},
+ {Line: 405, Value: "bytes.EqualFold($x, $x)"},
+ {Line: 406, Value: "bytes.HasPrefix($x, $x)"},
+ {Line: 407, Value: "bytes.HasSuffix($x, $x)"},
+ {Line: 408, Value: "bytes.Index($x, $x)"},
+ {Line: 409, Value: "bytes.LastIndex($x, $x)"},
+ {Line: 410, Value: "bytes.Split($x, $x)"},
+ {Line: 411, Value: "bytes.SplitAfter($x, $x)"},
+ {Line: 412, Value: "bytes.SplitAfterN($x, $x, $_)"},
+ {Line: 413, Value: "bytes.SplitN($x, $x, $_)"},
+ {Line: 414, Value: "bytes.Replace($_, $x, $x, $_)"},
+ {Line: 415, Value: "bytes.ReplaceAll($_, $x, $x)"},
+ {Line: 416, Value: "types.Identical($x, $x)"},
+ {Line: 417, Value: "types.IdenticalIgnoreTags($x, $x)"},
+ {Line: 418, Value: "draw.Draw($x, $_, $x, $_, $_)"},
},
ReportTemplate: "suspicious duplicated args in $$",
- WhereExpr: ir.FilterExpr{Line: 413, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ WhereExpr: ir.FilterExpr{Line: 419, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
},
},
},
{
- Line: 421,
+ Line: 427,
Name: "returnAfterHttpError",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -1416,14 +1440,14 @@ var PrecompiledRules = &ir.File{
DocBefore: "if err != nil { http.Error(...); }",
DocAfter: "if err != nil { http.Error(...); return; }",
Rules: []ir.Rule{{
- Line: 422,
- SyntaxPatterns: []ir.PatternString{{Line: 422, Value: "if $_ { $*_; http.Error($w, $err, $code) }"}},
+ Line: 428,
+ SyntaxPatterns: []ir.PatternString{{Line: 428, Value: "if $_ { $*_; http.Error($w, $err, $code) }"}},
ReportTemplate: "Possibly return is missed after the http.Error call",
LocationVar: "w",
}},
},
{
- Line: 431,
+ Line: 437,
Name: "preferFilepathJoin",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -1431,35 +1455,35 @@ var PrecompiledRules = &ir.File{
DocBefore: "x + string(os.PathSeparator) + y",
DocAfter: "filepath.Join(x, y)",
Rules: []ir.Rule{{
- Line: 432,
- SyntaxPatterns: []ir.PatternString{{Line: 432, Value: "$x + string(os.PathSeparator) + $y"}},
+ Line: 438,
+ SyntaxPatterns: []ir.PatternString{{Line: 438, 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: 433,
+ Line: 439,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Type.Is(`string`) && m[\"y\"].Type.Is(`string`)",
Args: []ir.FilterExpr{
{
- Line: 433,
+ Line: 439,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`string`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 433, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 439, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
{
- Line: 433,
+ Line: 439,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"y\"].Type.Is(`string`)",
Value: "y",
- Args: []ir.FilterExpr{{Line: 433, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 439, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
},
},
}},
},
{
- Line: 442,
+ Line: 448,
Name: "preferStringWriter",
MatcherName: "m",
DocTags: []string{"performance", "experimental"},
@@ -1468,35 +1492,35 @@ var PrecompiledRules = &ir.File{
DocAfter: "w.WriteString(\"foo\")",
Rules: []ir.Rule{
{
- Line: 443,
- SyntaxPatterns: []ir.PatternString{{Line: 443, Value: "$w.Write([]byte($s))"}},
+ Line: 449,
+ SyntaxPatterns: []ir.PatternString{{Line: 449, Value: "$w.Write([]byte($s))"}},
ReportTemplate: "$w.WriteString($s) should be preferred to the $$",
SuggestTemplate: "$w.WriteString($s)",
WhereExpr: ir.FilterExpr{
- Line: 444,
+ Line: 450,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.StringWriter\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 444, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
+ Args: []ir.FilterExpr{{Line: 450, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
},
},
{
- Line: 448,
- SyntaxPatterns: []ir.PatternString{{Line: 448, Value: "io.WriteString($w, $s)"}},
+ Line: 454,
+ SyntaxPatterns: []ir.PatternString{{Line: 454, Value: "io.WriteString($w, $s)"}},
ReportTemplate: "$w.WriteString($s) should be preferred to the $$",
SuggestTemplate: "$w.WriteString($s)",
WhereExpr: ir.FilterExpr{
- Line: 449,
+ Line: 455,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"w\"].Type.Implements(\"io.StringWriter\")",
Value: "w",
- Args: []ir.FilterExpr{{Line: 449, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
+ Args: []ir.FilterExpr{{Line: 455, Op: ir.FilterStringOp, Src: "\"io.StringWriter\"", Value: "io.StringWriter"}},
},
},
},
},
{
- Line: 458,
+ Line: 464,
Name: "sliceClear",
MatcherName: "m",
DocTags: []string{"performance", "experimental"},
@@ -1504,22 +1528,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: 459,
- SyntaxPatterns: []ir.PatternString{{Line: 459, Value: "for $i := 0; $i < len($xs); $i++ { $xs[$i] = $zero }"}},
+ Line: 465,
+ SyntaxPatterns: []ir.PatternString{{Line: 465, 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: 460,
+ Line: 466,
Op: ir.FilterEqOp,
Src: "m[\"zero\"].Value.Int() == 0",
Args: []ir.FilterExpr{
{
- Line: 460,
+ Line: 466,
Op: ir.FilterVarValueIntOp,
Src: "m[\"zero\"].Value.Int()",
Value: "zero",
},
{
- Line: 460,
+ Line: 466,
Op: ir.FilterIntOp,
Src: "0",
Value: int64(0),
@@ -1529,7 +1553,7 @@ var PrecompiledRules = &ir.File{
}},
},
{
- Line: 468,
+ Line: 474,
Name: "syncMapLoadAndDelete",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -1537,33 +1561,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: 469,
- SyntaxPatterns: []ir.PatternString{{Line: 469, Value: "$_, $ok := $m.Load($k); if $ok { $m.Delete($k); $*_ }"}},
+ Line: 475,
+ SyntaxPatterns: []ir.PatternString{{Line: 475, Value: "$_, $ok := $m.Load($k); if $ok { $m.Delete($k); $*_ }"}},
ReportTemplate: "use $m.LoadAndDelete to perform load+delete operations atomically",
WhereExpr: ir.FilterExpr{
- Line: 470,
+ Line: 476,
Op: ir.FilterAndOp,
Src: "m.GoVersion().GreaterEqThan(\"1.15\") &&\n\tm[\"m\"].Type.Is(`*sync.Map`)",
Args: []ir.FilterExpr{
{
- Line: 470,
+ Line: 476,
Op: ir.FilterGoVersionGreaterEqThanOp,
Src: "m.GoVersion().GreaterEqThan(\"1.15\")",
Value: "1.15",
},
{
- Line: 471,
+ Line: 477,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"m\"].Type.Is(`*sync.Map`)",
Value: "m",
- Args: []ir.FilterExpr{{Line: 471, Op: ir.FilterStringOp, Src: "`*sync.Map`", Value: "*sync.Map"}},
+ Args: []ir.FilterExpr{{Line: 477, Op: ir.FilterStringOp, Src: "`*sync.Map`", Value: "*sync.Map"}},
},
},
},
}},
},
{
- Line: 479,
+ Line: 485,
Name: "sprintfQuotedString",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -1571,34 +1595,34 @@ var PrecompiledRules = &ir.File{
DocBefore: "fmt.Sprintf(`\"%s\"`, s)",
DocAfter: "fmt.Sprintf(`%q`, s)",
Rules: []ir.Rule{{
- Line: 480,
- SyntaxPatterns: []ir.PatternString{{Line: 480, Value: "fmt.Sprintf($s, $*_)"}},
+ Line: 486,
+ SyntaxPatterns: []ir.PatternString{{Line: 486, Value: "fmt.Sprintf($s, $*_)"}},
ReportTemplate: "use %q instead of \"%s\" for quoted strings",
WhereExpr: ir.FilterExpr{
- Line: 481,
+ Line: 487,
Op: ir.FilterOrOp,
Src: "m[\"s\"].Text.Matches(\"^`.*\\\"%s\\\".*`$\") ||\n\tm[\"s\"].Text.Matches(`^\".*\\\\\"%s\\\\\".*\"$`)",
Args: []ir.FilterExpr{
{
- Line: 481,
+ Line: 487,
Op: ir.FilterVarTextMatchesOp,
Src: "m[\"s\"].Text.Matches(\"^`.*\\\"%s\\\".*`$\")",
Value: "s",
- Args: []ir.FilterExpr{{Line: 481, Op: ir.FilterStringOp, Src: "\"^`.*\\\"%s\\\".*`$\"", Value: "^`.*\"%s\".*`$"}},
+ Args: []ir.FilterExpr{{Line: 487, Op: ir.FilterStringOp, Src: "\"^`.*\\\"%s\\\".*`$\"", Value: "^`.*\"%s\".*`$"}},
},
{
- Line: 482,
+ Line: 488,
Op: ir.FilterVarTextMatchesOp,
Src: "m[\"s\"].Text.Matches(`^\".*\\\\\"%s\\\\\".*\"$`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 482, Op: ir.FilterStringOp, Src: "`^\".*\\\\\"%s\\\\\".*\"$`", Value: "^\".*\\\\\"%s\\\\\".*\"$"}},
+ Args: []ir.FilterExpr{{Line: 488, Op: ir.FilterStringOp, Src: "`^\".*\\\\\"%s\\\\\".*\"$`", Value: "^\".*\\\\\"%s\\\\\".*\"$"}},
},
},
},
}},
},
{
- Line: 490,
+ Line: 496,
Name: "offBy1",
MatcherName: "m",
DocTags: []string{"diagnostic"},
@@ -1607,80 +1631,80 @@ var PrecompiledRules = &ir.File{
DocAfter: "xs[len(xs)-1]",
Rules: []ir.Rule{
{
- Line: 491,
- SyntaxPatterns: []ir.PatternString{{Line: 491, Value: "$x[len($x)]"}},
+ Line: 497,
+ SyntaxPatterns: []ir.PatternString{{Line: 497, 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: 492,
+ Line: 498,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"x\"].Type.Is(`[]$_`)",
Args: []ir.FilterExpr{
- {Line: 492, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ {Line: 498, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
{
- Line: 492,
+ Line: 498,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`[]$_`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 492, Op: ir.FilterStringOp, Src: "`[]$_`", Value: "[]$_"}},
+ Args: []ir.FilterExpr{{Line: 498, Op: ir.FilterStringOp, Src: "`[]$_`", Value: "[]$_"}},
},
},
},
},
{
- Line: 499,
+ Line: 505,
SyntaxPatterns: []ir.PatternString{
- {Line: 500, Value: "$i := strings.Index($s, $_); $_ := $slicing[$i:]"},
- {Line: 501, Value: "$i := strings.Index($s, $_); $_ = $slicing[$i:]"},
- {Line: 502, Value: "$i := bytes.Index($s, $_); $_ := $slicing[$i:]"},
- {Line: 503, Value: "$i := bytes.Index($s, $_); $_ = $slicing[$i:]"},
+ {Line: 506, Value: "$i := strings.Index($s, $_); $_ := $slicing[$i:]"},
+ {Line: 507, Value: "$i := strings.Index($s, $_); $_ = $slicing[$i:]"},
+ {Line: 508, Value: "$i := bytes.Index($s, $_); $_ := $slicing[$i:]"},
+ {Line: 509, Value: "$i := bytes.Index($s, $_); $_ = $slicing[$i:]"},
},
ReportTemplate: "Index() can return -1; maybe you wanted to do $s[$i+1:]",
WhereExpr: ir.FilterExpr{
- Line: 504,
+ Line: 510,
Op: ir.FilterEqOp,
Src: "m[\"s\"].Text == m[\"slicing\"].Text",
Args: []ir.FilterExpr{
- {Line: 504, Op: ir.FilterVarTextOp, Src: "m[\"s\"].Text", Value: "s"},
- {Line: 504, Op: ir.FilterVarTextOp, Src: "m[\"slicing\"].Text", Value: "slicing"},
+ {Line: 510, Op: ir.FilterVarTextOp, Src: "m[\"s\"].Text", Value: "s"},
+ {Line: 510, Op: ir.FilterVarTextOp, Src: "m[\"slicing\"].Text", Value: "slicing"},
},
},
LocationVar: "slicing",
},
{
- Line: 508,
+ Line: 514,
SyntaxPatterns: []ir.PatternString{
- {Line: 509, Value: "$i := strings.Index($s, $_); $_ := $slicing[:$i]"},
- {Line: 510, Value: "$i := strings.Index($s, $_); $_ = $slicing[:$i]"},
- {Line: 511, Value: "$i := bytes.Index($s, $_); $_ := $slicing[:$i]"},
- {Line: 512, Value: "$i := bytes.Index($s, $_); $_ = $slicing[:$i]"},
+ {Line: 515, Value: "$i := strings.Index($s, $_); $_ := $slicing[:$i]"},
+ {Line: 516, Value: "$i := strings.Index($s, $_); $_ = $slicing[:$i]"},
+ {Line: 517, Value: "$i := bytes.Index($s, $_); $_ := $slicing[:$i]"},
+ {Line: 518, Value: "$i := bytes.Index($s, $_); $_ = $slicing[:$i]"},
},
ReportTemplate: "Index() can return -1; maybe you wanted to do $s[:$i+1]",
WhereExpr: ir.FilterExpr{
- Line: 513,
+ Line: 519,
Op: ir.FilterEqOp,
Src: "m[\"s\"].Text == m[\"slicing\"].Text",
Args: []ir.FilterExpr{
- {Line: 513, Op: ir.FilterVarTextOp, Src: "m[\"s\"].Text", Value: "s"},
- {Line: 513, Op: ir.FilterVarTextOp, Src: "m[\"slicing\"].Text", Value: "slicing"},
+ {Line: 519, Op: ir.FilterVarTextOp, Src: "m[\"s\"].Text", Value: "s"},
+ {Line: 519, Op: ir.FilterVarTextOp, Src: "m[\"slicing\"].Text", Value: "slicing"},
},
},
LocationVar: "slicing",
},
{
- Line: 517,
+ Line: 523,
SyntaxPatterns: []ir.PatternString{
- {Line: 518, Value: "$s[strings.Index($s, $_):]"},
- {Line: 519, Value: "$s[:strings.Index($s, $_)]"},
- {Line: 520, Value: "$s[bytes.Index($s, $_):]"},
- {Line: 521, Value: "$s[:bytes.Index($s, $_)]"},
+ {Line: 524, Value: "$s[strings.Index($s, $_):]"},
+ {Line: 525, Value: "$s[:strings.Index($s, $_)]"},
+ {Line: 526, Value: "$s[bytes.Index($s, $_):]"},
+ {Line: 527, Value: "$s[:bytes.Index($s, $_)]"},
},
ReportTemplate: "Index() can return -1; maybe you wanted to do Index()+1",
},
},
},
{
- Line: 529,
+ Line: 535,
Name: "unslice",
MatcherName: "m",
DocTags: []string{"style"},
@@ -1688,35 +1712,35 @@ var PrecompiledRules = &ir.File{
DocBefore: "copy(b[:], values...)",
DocAfter: "copy(b, values...)",
Rules: []ir.Rule{{
- Line: 530,
- SyntaxPatterns: []ir.PatternString{{Line: 530, Value: "$s[:]"}},
+ Line: 536,
+ SyntaxPatterns: []ir.PatternString{{Line: 536, Value: "$s[:]"}},
ReportTemplate: "could simplify $$ to $s",
SuggestTemplate: "$s",
WhereExpr: ir.FilterExpr{
- Line: 531,
+ Line: 537,
Op: ir.FilterOrOp,
Src: "m[\"s\"].Type.Is(`string`) || m[\"s\"].Type.Is(`[]$_`)",
Args: []ir.FilterExpr{
{
- Line: 531,
+ Line: 537,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`string`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 531, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
+ Args: []ir.FilterExpr{{Line: 537, Op: ir.FilterStringOp, Src: "`string`", Value: "string"}},
},
{
- Line: 531,
+ Line: 537,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"s\"].Type.Is(`[]$_`)",
Value: "s",
- Args: []ir.FilterExpr{{Line: 531, Op: ir.FilterStringOp, Src: "`[]$_`", Value: "[]$_"}},
+ Args: []ir.FilterExpr{{Line: 537, Op: ir.FilterStringOp, Src: "`[]$_`", Value: "[]$_"}},
},
},
},
}},
},
{
- Line: 540,
+ Line: 546,
Name: "yodaStyleExpr",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -1725,105 +1749,105 @@ var PrecompiledRules = &ir.File{
DocAfter: "return ptr != nil",
Rules: []ir.Rule{
{
- Line: 541,
- SyntaxPatterns: []ir.PatternString{{Line: 541, Value: "$constval != $x"}},
+ Line: 547,
+ SyntaxPatterns: []ir.PatternString{{Line: 547, Value: "$constval != $x"}},
ReportTemplate: "consider to change order in expression to $x != $constval",
WhereExpr: ir.FilterExpr{
- Line: 541,
+ Line: 547,
Op: ir.FilterAndOp,
Src: "m[\"constval\"].Node.Is(`BasicLit`) && !m[\"x\"].Node.Is(`BasicLit`)",
Args: []ir.FilterExpr{
{
- Line: 541,
+ Line: 547,
Op: ir.FilterVarNodeIsOp,
Src: "m[\"constval\"].Node.Is(`BasicLit`)",
Value: "constval",
- Args: []ir.FilterExpr{{Line: 541, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
+ Args: []ir.FilterExpr{{Line: 547, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
},
{
- Line: 541,
+ Line: 547,
Op: ir.FilterNotOp,
Src: "!m[\"x\"].Node.Is(`BasicLit`)",
Args: []ir.FilterExpr{{
- Line: 541,
+ Line: 547,
Op: ir.FilterVarNodeIsOp,
Src: "m[\"x\"].Node.Is(`BasicLit`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 541, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
+ Args: []ir.FilterExpr{{Line: 547, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
}},
},
},
},
},
{
- Line: 543,
- SyntaxPatterns: []ir.PatternString{{Line: 543, Value: "$constval == $x"}},
+ Line: 549,
+ SyntaxPatterns: []ir.PatternString{{Line: 549, Value: "$constval == $x"}},
ReportTemplate: "consider to change order in expression to $x == $constval",
WhereExpr: ir.FilterExpr{
- Line: 543,
+ Line: 549,
Op: ir.FilterAndOp,
Src: "m[\"constval\"].Node.Is(`BasicLit`) && !m[\"x\"].Node.Is(`BasicLit`)",
Args: []ir.FilterExpr{
{
- Line: 543,
+ Line: 549,
Op: ir.FilterVarNodeIsOp,
Src: "m[\"constval\"].Node.Is(`BasicLit`)",
Value: "constval",
- Args: []ir.FilterExpr{{Line: 543, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
+ Args: []ir.FilterExpr{{Line: 549, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
},
{
- Line: 543,
+ Line: 549,
Op: ir.FilterNotOp,
Src: "!m[\"x\"].Node.Is(`BasicLit`)",
Args: []ir.FilterExpr{{
- Line: 543,
+ Line: 549,
Op: ir.FilterVarNodeIsOp,
Src: "m[\"x\"].Node.Is(`BasicLit`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 543, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
+ Args: []ir.FilterExpr{{Line: 549, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
}},
},
},
},
},
{
- Line: 546,
- SyntaxPatterns: []ir.PatternString{{Line: 546, Value: "nil != $x"}},
+ Line: 552,
+ SyntaxPatterns: []ir.PatternString{{Line: 552, Value: "nil != $x"}},
ReportTemplate: "consider to change order in expression to $x != nil",
WhereExpr: ir.FilterExpr{
- Line: 546,
+ Line: 552,
Op: ir.FilterNotOp,
Src: "!m[\"x\"].Node.Is(`BasicLit`)",
Args: []ir.FilterExpr{{
- Line: 546,
+ Line: 552,
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: 552, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
}},
},
},
{
- Line: 548,
- SyntaxPatterns: []ir.PatternString{{Line: 548, Value: "nil == $x"}},
+ Line: 554,
+ SyntaxPatterns: []ir.PatternString{{Line: 554, Value: "nil == $x"}},
ReportTemplate: "consider to change order in expression to $x == nil",
WhereExpr: ir.FilterExpr{
- Line: 548,
+ Line: 554,
Op: ir.FilterNotOp,
Src: "!m[\"x\"].Node.Is(`BasicLit`)",
Args: []ir.FilterExpr{{
- Line: 548,
+ Line: 554,
Op: ir.FilterVarNodeIsOp,
Src: "m[\"x\"].Node.Is(`BasicLit`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 548, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
+ Args: []ir.FilterExpr{{Line: 554, Op: ir.FilterStringOp, Src: "`BasicLit`", Value: "BasicLit"}},
}},
},
},
},
},
{
- Line: 556,
+ Line: 562,
Name: "equalFold",
MatcherName: "m",
DocTags: []string{"performance", "experimental"},
@@ -1832,114 +1856,114 @@ var PrecompiledRules = &ir.File{
DocAfter: "strings.EqualFold(x, y)",
Rules: []ir.Rule{
{
- Line: 565,
+ Line: 571,
SyntaxPatterns: []ir.PatternString{
- {Line: 566, Value: "strings.ToLower($x) == $y"},
- {Line: 567, Value: "strings.ToLower($x) == strings.ToLower($y)"},
- {Line: 568, Value: "$x == strings.ToLower($y)"},
- {Line: 569, Value: "strings.ToUpper($x) == $y"},
- {Line: 570, Value: "strings.ToUpper($x) == strings.ToUpper($y)"},
- {Line: 571, Value: "$x == strings.ToUpper($y)"},
+ {Line: 572, Value: "strings.ToLower($x) == $y"},
+ {Line: 573, Value: "strings.ToLower($x) == strings.ToLower($y)"},
+ {Line: 574, Value: "$x == strings.ToLower($y)"},
+ {Line: 575, Value: "strings.ToUpper($x) == $y"},
+ {Line: 576, Value: "strings.ToUpper($x) == strings.ToUpper($y)"},
+ {Line: 577, Value: "$x == strings.ToUpper($y)"},
},
ReportTemplate: "consider replacing with strings.EqualFold($x, $y)",
SuggestTemplate: "strings.EqualFold($x, $y)",
WhereExpr: ir.FilterExpr{
- Line: 572,
+ Line: 578,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure && m[\"x\"].Text != m[\"y\"].Text",
Args: []ir.FilterExpr{
{
- Line: 572,
+ Line: 578,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure",
Args: []ir.FilterExpr{
- {Line: 572, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
- {Line: 572, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
+ {Line: 578, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ {Line: 578, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
},
},
{
- Line: 572,
+ Line: 578,
Op: ir.FilterNeqOp,
Src: "m[\"x\"].Text != m[\"y\"].Text",
Args: []ir.FilterExpr{
- {Line: 572, Op: ir.FilterVarTextOp, Src: "m[\"x\"].Text", Value: "x"},
- {Line: 572, Op: ir.FilterVarTextOp, Src: "m[\"y\"].Text", Value: "y"},
+ {Line: 578, Op: ir.FilterVarTextOp, Src: "m[\"x\"].Text", Value: "x"},
+ {Line: 578, Op: ir.FilterVarTextOp, Src: "m[\"y\"].Text", Value: "y"},
},
},
},
},
},
{
- Line: 577,
+ Line: 583,
SyntaxPatterns: []ir.PatternString{
- {Line: 578, Value: "strings.ToLower($x) != $y"},
- {Line: 579, Value: "strings.ToLower($x) != strings.ToLower($y)"},
- {Line: 580, Value: "$x != strings.ToLower($y)"},
- {Line: 581, Value: "strings.ToUpper($x) != $y"},
- {Line: 582, Value: "strings.ToUpper($x) != strings.ToUpper($y)"},
- {Line: 583, Value: "$x != strings.ToUpper($y)"},
+ {Line: 584, Value: "strings.ToLower($x) != $y"},
+ {Line: 585, Value: "strings.ToLower($x) != strings.ToLower($y)"},
+ {Line: 586, Value: "$x != strings.ToLower($y)"},
+ {Line: 587, Value: "strings.ToUpper($x) != $y"},
+ {Line: 588, Value: "strings.ToUpper($x) != strings.ToUpper($y)"},
+ {Line: 589, Value: "$x != strings.ToUpper($y)"},
},
ReportTemplate: "consider replacing with !strings.EqualFold($x, $y)",
SuggestTemplate: "!strings.EqualFold($x, $y)",
WhereExpr: ir.FilterExpr{
- Line: 584,
+ Line: 590,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure && m[\"x\"].Text != m[\"y\"].Text",
Args: []ir.FilterExpr{
{
- Line: 584,
+ Line: 590,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure",
Args: []ir.FilterExpr{
- {Line: 584, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
- {Line: 584, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
+ {Line: 590, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ {Line: 590, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
},
},
{
- Line: 584,
+ Line: 590,
Op: ir.FilterNeqOp,
Src: "m[\"x\"].Text != m[\"y\"].Text",
Args: []ir.FilterExpr{
- {Line: 584, Op: ir.FilterVarTextOp, Src: "m[\"x\"].Text", Value: "x"},
- {Line: 584, Op: ir.FilterVarTextOp, Src: "m[\"y\"].Text", Value: "y"},
+ {Line: 590, Op: ir.FilterVarTextOp, Src: "m[\"x\"].Text", Value: "x"},
+ {Line: 590, Op: ir.FilterVarTextOp, Src: "m[\"y\"].Text", Value: "y"},
},
},
},
},
},
{
- Line: 589,
+ Line: 595,
SyntaxPatterns: []ir.PatternString{
- {Line: 590, Value: "bytes.Equal(bytes.ToLower($x), $y)"},
- {Line: 591, Value: "bytes.Equal(bytes.ToLower($x), bytes.ToLower($y))"},
- {Line: 592, Value: "bytes.Equal($x, bytes.ToLower($y))"},
- {Line: 593, Value: "bytes.Equal(bytes.ToUpper($x), $y)"},
- {Line: 594, Value: "bytes.Equal(bytes.ToUpper($x), bytes.ToUpper($y))"},
- {Line: 595, Value: "bytes.Equal($x, bytes.ToUpper($y))"},
+ {Line: 596, Value: "bytes.Equal(bytes.ToLower($x), $y)"},
+ {Line: 597, Value: "bytes.Equal(bytes.ToLower($x), bytes.ToLower($y))"},
+ {Line: 598, Value: "bytes.Equal($x, bytes.ToLower($y))"},
+ {Line: 599, Value: "bytes.Equal(bytes.ToUpper($x), $y)"},
+ {Line: 600, Value: "bytes.Equal(bytes.ToUpper($x), bytes.ToUpper($y))"},
+ {Line: 601, Value: "bytes.Equal($x, bytes.ToUpper($y))"},
},
ReportTemplate: "consider replacing with bytes.EqualFold($x, $y)",
SuggestTemplate: "bytes.EqualFold($x, $y)",
WhereExpr: ir.FilterExpr{
- Line: 596,
+ Line: 602,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure && m[\"x\"].Text != m[\"y\"].Text",
Args: []ir.FilterExpr{
{
- Line: 596,
+ Line: 602,
Op: ir.FilterAndOp,
Src: "m[\"x\"].Pure && m[\"y\"].Pure",
Args: []ir.FilterExpr{
- {Line: 596, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
- {Line: 596, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
+ {Line: 602, Op: ir.FilterVarPureOp, Src: "m[\"x\"].Pure", Value: "x"},
+ {Line: 602, Op: ir.FilterVarPureOp, Src: "m[\"y\"].Pure", Value: "y"},
},
},
{
- Line: 596,
+ Line: 602,
Op: ir.FilterNeqOp,
Src: "m[\"x\"].Text != m[\"y\"].Text",
Args: []ir.FilterExpr{
- {Line: 596, Op: ir.FilterVarTextOp, Src: "m[\"x\"].Text", Value: "x"},
- {Line: 596, Op: ir.FilterVarTextOp, Src: "m[\"y\"].Text", Value: "y"},
+ {Line: 602, Op: ir.FilterVarTextOp, Src: "m[\"x\"].Text", Value: "x"},
+ {Line: 602, Op: ir.FilterVarTextOp, Src: "m[\"y\"].Text", Value: "y"},
},
},
},
@@ -1948,7 +1972,7 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 605,
+ Line: 611,
Name: "argOrder",
MatcherName: "m",
DocTags: []string{"diagnostic"},
@@ -1956,45 +1980,45 @@ var PrecompiledRules = &ir.File{
DocBefore: "strings.HasPrefix(\"#\", userpass)",
DocAfter: "strings.HasPrefix(userpass, \"#\")",
Rules: []ir.Rule{{
- Line: 606,
+ Line: 612,
SyntaxPatterns: []ir.PatternString{
- {Line: 607, Value: "strings.HasPrefix($lit, $s)"},
- {Line: 608, Value: "bytes.HasPrefix($lit, $s)"},
- {Line: 609, Value: "strings.HasSuffix($lit, $s)"},
- {Line: 610, Value: "bytes.HasSuffix($lit, $s)"},
- {Line: 611, Value: "strings.Contains($lit, $s)"},
- {Line: 612, Value: "bytes.Contains($lit, $s)"},
- {Line: 613, Value: "strings.TrimPrefix($lit, $s)"},
- {Line: 614, Value: "bytes.TrimPrefix($lit, $s)"},
- {Line: 615, Value: "strings.TrimSuffix($lit, $s)"},
- {Line: 616, Value: "bytes.TrimSuffix($lit, $s)"},
- {Line: 617, Value: "strings.Split($lit, $s)"},
- {Line: 618, Value: "bytes.Split($lit, $s)"},
+ {Line: 613, Value: "strings.HasPrefix($lit, $s)"},
+ {Line: 614, Value: "bytes.HasPrefix($lit, $s)"},
+ {Line: 615, Value: "strings.HasSuffix($lit, $s)"},
+ {Line: 616, Value: "bytes.HasSuffix($lit, $s)"},
+ {Line: 617, Value: "strings.Contains($lit, $s)"},
+ {Line: 618, Value: "bytes.Contains($lit, $s)"},
+ {Line: 619, Value: "strings.TrimPrefix($lit, $s)"},
+ {Line: 620, Value: "bytes.TrimPrefix($lit, $s)"},
+ {Line: 621, Value: "strings.TrimSuffix($lit, $s)"},
+ {Line: 622, Value: "bytes.TrimSuffix($lit, $s)"},
+ {Line: 623, Value: "strings.Split($lit, $s)"},
+ {Line: 624, Value: "bytes.Split($lit, $s)"},
},
ReportTemplate: "$lit and $s arguments order looks reversed",
WhereExpr: ir.FilterExpr{
- Line: 619,
+ Line: 625,
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: 619,
+ Line: 625,
Op: ir.FilterAndOp,
Src: "(m[\"lit\"].Const || m[\"lit\"].ConstSlice) &&\n\t!(m[\"s\"].Const || m[\"s\"].ConstSlice)",
Args: []ir.FilterExpr{
{
- Line: 619,
+ Line: 625,
Op: ir.FilterOrOp,
Src: "(m[\"lit\"].Const || m[\"lit\"].ConstSlice)",
Args: []ir.FilterExpr{
{
- Line: 619,
+ Line: 625,
Op: ir.FilterVarConstOp,
Src: "m[\"lit\"].Const",
Value: "lit",
},
{
- Line: 619,
+ Line: 625,
Op: ir.FilterVarConstSliceOp,
Src: "m[\"lit\"].ConstSlice",
Value: "lit",
@@ -2002,22 +2026,22 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 620,
+ Line: 626,
Op: ir.FilterNotOp,
Src: "!(m[\"s\"].Const || m[\"s\"].ConstSlice)",
Args: []ir.FilterExpr{{
- Line: 620,
+ Line: 626,
Op: ir.FilterOrOp,
Src: "(m[\"s\"].Const || m[\"s\"].ConstSlice)",
Args: []ir.FilterExpr{
{
- Line: 620,
+ Line: 626,
Op: ir.FilterVarConstOp,
Src: "m[\"s\"].Const",
Value: "s",
},
{
- Line: 620,
+ Line: 626,
Op: ir.FilterVarConstSliceOp,
Src: "m[\"s\"].ConstSlice",
Value: "s",
@@ -2028,15 +2052,15 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 621,
+ Line: 627,
Op: ir.FilterNotOp,
Src: "!m[\"lit\"].Node.Is(`Ident`)",
Args: []ir.FilterExpr{{
- Line: 621,
+ Line: 627,
Op: ir.FilterVarNodeIsOp,
Src: "m[\"lit\"].Node.Is(`Ident`)",
Value: "lit",
- Args: []ir.FilterExpr{{Line: 621, Op: ir.FilterStringOp, Src: "`Ident`", Value: "Ident"}},
+ Args: []ir.FilterExpr{{Line: 627, Op: ir.FilterStringOp, Src: "`Ident`", Value: "Ident"}},
}},
},
},
@@ -2044,7 +2068,7 @@ var PrecompiledRules = &ir.File{
}},
},
{
- Line: 629,
+ Line: 635,
Name: "stringConcatSimplify",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -2053,27 +2077,27 @@ var PrecompiledRules = &ir.File{
DocAfter: "x + \"_\" + y",
Rules: []ir.Rule{
{
- Line: 630,
- SyntaxPatterns: []ir.PatternString{{Line: 630, Value: "strings.Join([]string{$x, $y}, \"\")"}},
+ Line: 636,
+ SyntaxPatterns: []ir.PatternString{{Line: 636, Value: "strings.Join([]string{$x, $y}, \"\")"}},
ReportTemplate: "suggestion: $x + $y",
SuggestTemplate: "$x + $y",
},
{
- Line: 631,
- SyntaxPatterns: []ir.PatternString{{Line: 631, Value: "strings.Join([]string{$x, $y, $z}, \"\")"}},
+ Line: 637,
+ SyntaxPatterns: []ir.PatternString{{Line: 637, Value: "strings.Join([]string{$x, $y, $z}, \"\")"}},
ReportTemplate: "suggestion: $x + $y + $z",
SuggestTemplate: "$x + $y + $z",
},
{
- Line: 632,
- SyntaxPatterns: []ir.PatternString{{Line: 632, Value: "strings.Join([]string{$x, $y}, $glue)"}},
+ Line: 638,
+ SyntaxPatterns: []ir.PatternString{{Line: 638, Value: "strings.Join([]string{$x, $y}, $glue)"}},
ReportTemplate: "suggestion: $x + $glue + $y",
SuggestTemplate: "$x + $glue + $y",
},
},
},
{
- Line: 639,
+ Line: 645,
Name: "timeExprSimplify",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -2082,39 +2106,39 @@ var PrecompiledRules = &ir.File{
DocAfter: "t.UnixMilli()",
Rules: []ir.Rule{
{
- Line: 644,
- SyntaxPatterns: []ir.PatternString{{Line: 644, Value: "$t.Unix() / 1000"}},
+ Line: 650,
+ SyntaxPatterns: []ir.PatternString{{Line: 650, Value: "$t.Unix() / 1000"}},
ReportTemplate: "use $t.UnixMilli() instead of $$",
SuggestTemplate: "$t.UnixMilli()",
WhereExpr: ir.FilterExpr{
- Line: 645,
+ Line: 651,
Op: ir.FilterAndOp,
Src: "m.GoVersion().GreaterEqThan(\"1.17\") && isTime(m[\"t\"])",
Args: []ir.FilterExpr{
{
- Line: 645,
+ Line: 651,
Op: ir.FilterGoVersionGreaterEqThanOp,
Src: "m.GoVersion().GreaterEqThan(\"1.17\")",
Value: "1.17",
},
{
- Line: 645,
+ Line: 651,
Op: ir.FilterOrOp,
Src: "isTime(m[\"t\"])",
Args: []ir.FilterExpr{
{
- Line: 645,
+ Line: 651,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"t\"].Type.Is(`time.Time`)",
Value: "t",
- Args: []ir.FilterExpr{{Line: 641, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
+ Args: []ir.FilterExpr{{Line: 647, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
},
{
- Line: 645,
+ Line: 651,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"t\"].Type.Is(`*time.Time`)",
Value: "t",
- Args: []ir.FilterExpr{{Line: 641, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
+ Args: []ir.FilterExpr{{Line: 647, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
},
},
},
@@ -2122,39 +2146,39 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 649,
- SyntaxPatterns: []ir.PatternString{{Line: 649, Value: "$t.UnixNano() * 1000"}},
+ Line: 655,
+ SyntaxPatterns: []ir.PatternString{{Line: 655, Value: "$t.UnixNano() * 1000"}},
ReportTemplate: "use $t.UnixMicro() instead of $$",
SuggestTemplate: "$t.UnixMicro()",
WhereExpr: ir.FilterExpr{
- Line: 650,
+ Line: 656,
Op: ir.FilterAndOp,
Src: "m.GoVersion().GreaterEqThan(\"1.17\") && isTime(m[\"t\"])",
Args: []ir.FilterExpr{
{
- Line: 650,
+ Line: 656,
Op: ir.FilterGoVersionGreaterEqThanOp,
Src: "m.GoVersion().GreaterEqThan(\"1.17\")",
Value: "1.17",
},
{
- Line: 650,
+ Line: 656,
Op: ir.FilterOrOp,
Src: "isTime(m[\"t\"])",
Args: []ir.FilterExpr{
{
- Line: 650,
+ Line: 656,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"t\"].Type.Is(`time.Time`)",
Value: "t",
- Args: []ir.FilterExpr{{Line: 641, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
+ Args: []ir.FilterExpr{{Line: 647, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
},
{
- Line: 650,
+ Line: 656,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"t\"].Type.Is(`*time.Time`)",
Value: "t",
- Args: []ir.FilterExpr{{Line: 641, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
+ Args: []ir.FilterExpr{{Line: 647, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
},
},
},
@@ -2164,72 +2188,7 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 659,
- Name: "timeCmpSimplify",
- MatcherName: "m",
- DocTags: []string{"style", "experimental"},
- DocSummary: "Detects Before/After call of time.Time that can be simplified",
- DocBefore: "!t.Before(tt)",
- DocAfter: "t.After(tt)",
- Rules: []ir.Rule{
- {
- Line: 664,
- SyntaxPatterns: []ir.PatternString{{Line: 664, Value: "!$t.Before($tt)"}},
- ReportTemplate: "suggestion: $t.After($tt)",
- SuggestTemplate: "$t.After($tt)",
- WhereExpr: ir.FilterExpr{
- Line: 665,
- Op: ir.FilterOrOp,
- Src: "isTime(m[\"t\"])",
- Args: []ir.FilterExpr{
- {
- Line: 665,
- Op: ir.FilterVarTypeIsOp,
- Src: "m[\"t\"].Type.Is(`time.Time`)",
- Value: "t",
- Args: []ir.FilterExpr{{Line: 661, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
- },
- {
- Line: 665,
- Op: ir.FilterVarTypeIsOp,
- Src: "m[\"t\"].Type.Is(`*time.Time`)",
- Value: "t",
- Args: []ir.FilterExpr{{Line: 661, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
- },
- },
- },
- },
- {
- Line: 668,
- SyntaxPatterns: []ir.PatternString{{Line: 668, Value: "!$t.After($tt)"}},
- ReportTemplate: "suggestion: $t.Before($tt)",
- SuggestTemplate: "$t.Before($tt)",
- WhereExpr: ir.FilterExpr{
- Line: 669,
- Op: ir.FilterOrOp,
- Src: "isTime(m[\"t\"])",
- Args: []ir.FilterExpr{
- {
- Line: 669,
- Op: ir.FilterVarTypeIsOp,
- Src: "m[\"t\"].Type.Is(`time.Time`)",
- Value: "t",
- Args: []ir.FilterExpr{{Line: 661, Op: ir.FilterStringOp, Src: "`time.Time`", Value: "time.Time"}},
- },
- {
- Line: 669,
- Op: ir.FilterVarTypeIsOp,
- Src: "m[\"t\"].Type.Is(`*time.Time`)",
- Value: "t",
- Args: []ir.FilterExpr{{Line: 661, Op: ir.FilterStringOp, Src: "`*time.Time`", Value: "*time.Time"}},
- },
- },
- },
- },
- },
- },
- {
- Line: 677,
+ Line: 665,
Name: "exposedSyncMutex",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -2238,57 +2197,57 @@ var PrecompiledRules = &ir.File{
DocAfter: "type Foo struct{ ...; mu sync.Mutex; ... }",
Rules: []ir.Rule{
{
- Line: 682,
- SyntaxPatterns: []ir.PatternString{{Line: 682, Value: "type $x struct { $*_; sync.Mutex; $*_ }"}},
+ Line: 670,
+ SyntaxPatterns: []ir.PatternString{{Line: 670, Value: "type $x struct { $*_; sync.Mutex; $*_ }"}},
ReportTemplate: "don't embed sync.Mutex",
WhereExpr: ir.FilterExpr{
- Line: 683,
+ Line: 671,
Op: ir.FilterVarTextMatchesOp,
Src: "isExported(m[\"x\"])",
Value: "x",
- Args: []ir.FilterExpr{{Line: 679, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
+ Args: []ir.FilterExpr{{Line: 667, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
},
},
{
- Line: 686,
- SyntaxPatterns: []ir.PatternString{{Line: 686, Value: "type $x struct { $*_; *sync.Mutex; $*_ }"}},
+ Line: 674,
+ SyntaxPatterns: []ir.PatternString{{Line: 674, Value: "type $x struct { $*_; *sync.Mutex; $*_ }"}},
ReportTemplate: "don't embed *sync.Mutex",
WhereExpr: ir.FilterExpr{
- Line: 687,
+ Line: 675,
Op: ir.FilterVarTextMatchesOp,
Src: "isExported(m[\"x\"])",
Value: "x",
- Args: []ir.FilterExpr{{Line: 679, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
+ Args: []ir.FilterExpr{{Line: 667, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
},
},
{
- Line: 690,
- SyntaxPatterns: []ir.PatternString{{Line: 690, Value: "type $x struct { $*_; sync.RWMutex; $*_ }"}},
+ Line: 678,
+ SyntaxPatterns: []ir.PatternString{{Line: 678, Value: "type $x struct { $*_; sync.RWMutex; $*_ }"}},
ReportTemplate: "don't embed sync.RWMutex",
WhereExpr: ir.FilterExpr{
- Line: 691,
+ Line: 679,
Op: ir.FilterVarTextMatchesOp,
Src: "isExported(m[\"x\"])",
Value: "x",
- Args: []ir.FilterExpr{{Line: 679, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
+ Args: []ir.FilterExpr{{Line: 667, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
},
},
{
- Line: 694,
- SyntaxPatterns: []ir.PatternString{{Line: 694, Value: "type $x struct { $*_; *sync.RWMutex; $*_ }"}},
+ Line: 682,
+ SyntaxPatterns: []ir.PatternString{{Line: 682, Value: "type $x struct { $*_; *sync.RWMutex; $*_ }"}},
ReportTemplate: "don't embed *sync.RWMutex",
WhereExpr: ir.FilterExpr{
- Line: 695,
+ Line: 683,
Op: ir.FilterVarTextMatchesOp,
Src: "isExported(m[\"x\"])",
Value: "x",
- Args: []ir.FilterExpr{{Line: 679, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
+ Args: []ir.FilterExpr{{Line: 667, Op: ir.FilterStringOp, Src: "`^\\p{Lu}`", Value: "^\\p{Lu}"}},
},
},
},
},
{
- Line: 703,
+ Line: 691,
Name: "badSorting",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -2297,83 +2256,83 @@ var PrecompiledRules = &ir.File{
DocAfter: "sort.Strings(xs)",
Rules: []ir.Rule{
{
- Line: 704,
- SyntaxPatterns: []ir.PatternString{{Line: 704, Value: "$x = sort.IntSlice($x)"}},
+ Line: 692,
+ SyntaxPatterns: []ir.PatternString{{Line: 692, Value: "$x = sort.IntSlice($x)"}},
ReportTemplate: "suspicious sort.IntSlice usage, maybe sort.Ints was intended?",
SuggestTemplate: "sort.Ints($x)",
WhereExpr: ir.FilterExpr{
- Line: 705,
+ Line: 693,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`[]int`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 705, Op: ir.FilterStringOp, Src: "`[]int`", Value: "[]int"}},
+ Args: []ir.FilterExpr{{Line: 693, Op: ir.FilterStringOp, Src: "`[]int`", Value: "[]int"}},
},
},
{
- Line: 709,
- SyntaxPatterns: []ir.PatternString{{Line: 709, Value: "$x = sort.Float64Slice($x)"}},
+ Line: 697,
+ SyntaxPatterns: []ir.PatternString{{Line: 697, Value: "$x = sort.Float64Slice($x)"}},
ReportTemplate: "suspicious sort.Float64s usage, maybe sort.Float64s was intended?",
SuggestTemplate: "sort.Float64s($x)",
WhereExpr: ir.FilterExpr{
- Line: 710,
+ Line: 698,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`[]float64`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 710, Op: ir.FilterStringOp, Src: "`[]float64`", Value: "[]float64"}},
+ Args: []ir.FilterExpr{{Line: 698, Op: ir.FilterStringOp, Src: "`[]float64`", Value: "[]float64"}},
},
},
{
- Line: 714,
- SyntaxPatterns: []ir.PatternString{{Line: 714, Value: "$x = sort.StringSlice($x)"}},
+ Line: 702,
+ SyntaxPatterns: []ir.PatternString{{Line: 702, Value: "$x = sort.StringSlice($x)"}},
ReportTemplate: "suspicious sort.StringSlice usage, maybe sort.Strings was intended?",
SuggestTemplate: "sort.Strings($x)",
WhereExpr: ir.FilterExpr{
- Line: 715,
+ Line: 703,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"x\"].Type.Is(`[]string`)",
Value: "x",
- Args: []ir.FilterExpr{{Line: 715, Op: ir.FilterStringOp, Src: "`[]string`", Value: "[]string"}},
+ Args: []ir.FilterExpr{{Line: 703, Op: ir.FilterStringOp, Src: "`[]string`", Value: "[]string"}},
},
},
},
},
{
- Line: 724,
+ Line: 712,
Name: "externalErrorReassign",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
- DocSummary: "Detects suspicious reassigment of error from another package",
+ DocSummary: "Detects suspicious reassignment of error from another package",
DocBefore: "io.EOF = nil",
DocAfter: "/* don't do it */",
Rules: []ir.Rule{{
- Line: 725,
- SyntaxPatterns: []ir.PatternString{{Line: 725, Value: "$pkg.$err = $x"}},
- ReportTemplate: "suspicious reassigment of error from another package",
+ Line: 713,
+ SyntaxPatterns: []ir.PatternString{{Line: 713, Value: "$pkg.$err = $x"}},
+ ReportTemplate: "suspicious reassignment of error from another package",
WhereExpr: ir.FilterExpr{
- Line: 726,
+ Line: 714,
Op: ir.FilterAndOp,
Src: "m[\"err\"].Type.Is(`error`) && m[\"pkg\"].Object.Is(`PkgName`)",
Args: []ir.FilterExpr{
{
- Line: 726,
+ Line: 714,
Op: ir.FilterVarTypeIsOp,
Src: "m[\"err\"].Type.Is(`error`)",
Value: "err",
- Args: []ir.FilterExpr{{Line: 726, Op: ir.FilterStringOp, Src: "`error`", Value: "error"}},
+ Args: []ir.FilterExpr{{Line: 714, Op: ir.FilterStringOp, Src: "`error`", Value: "error"}},
},
{
- Line: 726,
+ Line: 714,
Op: ir.FilterVarObjectIsOp,
Src: "m[\"pkg\"].Object.Is(`PkgName`)",
Value: "pkg",
- Args: []ir.FilterExpr{{Line: 726, Op: ir.FilterStringOp, Src: "`PkgName`", Value: "PkgName"}},
+ Args: []ir.FilterExpr{{Line: 714, Op: ir.FilterStringOp, Src: "`PkgName`", Value: "PkgName"}},
},
},
},
}},
},
{
- Line: 734,
+ Line: 722,
Name: "emptyDecl",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -2382,24 +2341,24 @@ var PrecompiledRules = &ir.File{
DocAfter: "/* nothing */",
Rules: []ir.Rule{
{
- Line: 735,
- SyntaxPatterns: []ir.PatternString{{Line: 735, Value: "var()"}},
+ Line: 723,
+ SyntaxPatterns: []ir.PatternString{{Line: 723, Value: "var()"}},
ReportTemplate: "empty var() block",
},
{
- Line: 736,
- SyntaxPatterns: []ir.PatternString{{Line: 736, Value: "const()"}},
+ Line: 724,
+ SyntaxPatterns: []ir.PatternString{{Line: 724, Value: "const()"}},
ReportTemplate: "empty const() block",
},
{
- Line: 737,
- SyntaxPatterns: []ir.PatternString{{Line: 737, Value: "type()"}},
+ Line: 725,
+ SyntaxPatterns: []ir.PatternString{{Line: 725, Value: "type()"}},
ReportTemplate: "empty type() block",
},
},
},
{
- Line: 744,
+ Line: 732,
Name: "dynamicFmtString",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -2408,16 +2367,16 @@ var PrecompiledRules = &ir.File{
DocAfter: "fmt.Errorf(\"%s\", msg)",
Rules: []ir.Rule{
{
- Line: 745,
- SyntaxPatterns: []ir.PatternString{{Line: 745, Value: "fmt.Errorf($f)"}},
+ Line: 733,
+ SyntaxPatterns: []ir.PatternString{{Line: 733, Value: "fmt.Errorf($f)"}},
ReportTemplate: "use errors.New($f) or fmt.Errorf(\"%s\", $f) instead",
SuggestTemplate: "errors.New($f)",
WhereExpr: ir.FilterExpr{
- Line: 746,
+ Line: 734,
Op: ir.FilterNotOp,
Src: "!m[\"f\"].Const",
Args: []ir.FilterExpr{{
- Line: 746,
+ Line: 734,
Op: ir.FilterVarConstOp,
Src: "m[\"f\"].Const",
Value: "f",
@@ -2425,15 +2384,15 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 750,
- SyntaxPatterns: []ir.PatternString{{Line: 750, Value: "fmt.Errorf($f($*args))"}},
+ Line: 738,
+ SyntaxPatterns: []ir.PatternString{{Line: 738, Value: "fmt.Errorf($f($*args))"}},
ReportTemplate: "use errors.New($f($*args)) or fmt.Errorf(\"%s\", $f($*args)) instead",
SuggestTemplate: "errors.New($f($*args))",
},
},
},
{
- Line: 759,
+ Line: 747,
Name: "stringsCompare",
MatcherName: "m",
DocTags: []string{"style", "experimental"},
@@ -2442,25 +2401,25 @@ var PrecompiledRules = &ir.File{
DocAfter: "x < y",
Rules: []ir.Rule{
{
- Line: 760,
- SyntaxPatterns: []ir.PatternString{{Line: 760, Value: "strings.Compare($s1, $s2) == 0"}},
+ Line: 748,
+ SyntaxPatterns: []ir.PatternString{{Line: 748, Value: "strings.Compare($s1, $s2) == 0"}},
ReportTemplate: "suggestion: $s1 == $s2",
SuggestTemplate: "$s1 == $s2",
},
{
- Line: 763,
+ Line: 751,
SyntaxPatterns: []ir.PatternString{
- {Line: 763, Value: "strings.Compare($s1, $s2) == -1"},
- {Line: 764, Value: "strings.Compare($s1, $s2) < 0"},
+ {Line: 751, Value: "strings.Compare($s1, $s2) == -1"},
+ {Line: 752, Value: "strings.Compare($s1, $s2) < 0"},
},
ReportTemplate: "suggestion: $s1 < $s2",
SuggestTemplate: "$s1 < $s2",
},
{
- Line: 767,
+ Line: 755,
SyntaxPatterns: []ir.PatternString{
- {Line: 767, Value: "strings.Compare($s1, $s2) == 1"},
- {Line: 768, Value: "strings.Compare($s1, $s2) > 0"},
+ {Line: 755, Value: "strings.Compare($s1, $s2) == 1"},
+ {Line: 756, Value: "strings.Compare($s1, $s2) > 0"},
},
ReportTemplate: "suggestion: $s1 > $s2",
SuggestTemplate: "$s1 > $s2",
@@ -2468,7 +2427,7 @@ var PrecompiledRules = &ir.File{
},
},
{
- Line: 776,
+ Line: 764,
Name: "uncheckedInlineErr",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
@@ -2476,47 +2435,47 @@ var PrecompiledRules = &ir.File{
DocBefore: "if err := expr(); err2 != nil { /*...*/ }",
DocAfter: "if err := expr(); err != nil { /*...*/ }",
Rules: []ir.Rule{{
- Line: 777,
+ Line: 765,
SyntaxPatterns: []ir.PatternString{
- {Line: 778, Value: "if $err := $_($*_); $err2 != nil { $*_ }"},
- {Line: 779, Value: "if $err = $_($*_); $err2 != nil { $*_ }"},
- {Line: 780, Value: "if $*_, $err := $_($*_); $err2 != nil { $*_ }"},
- {Line: 781, Value: "if $*_, $err = $_($*_); $err2 != nil { $*_ }"},
+ {Line: 766, Value: "if $err := $_($*_); $err2 != nil { $*_ }"},
+ {Line: 767, Value: "if $err = $_($*_); $err2 != nil { $*_ }"},
+ {Line: 768, Value: "if $*_, $err := $_($*_); $err2 != nil { $*_ }"},
+ {Line: 769, Value: "if $*_, $err = $_($*_); $err2 != nil { $*_ }"},
},
ReportTemplate: "$err error is unchecked, maybe intended to check it instead of $err2",
WhereExpr: ir.FilterExpr{
- Line: 782,
+ Line: 770,
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: 782,
+ Line: 770,
Op: ir.FilterAndOp,
Src: "m[\"err\"].Type.Implements(\"error\") && m[\"err2\"].Type.Implements(\"error\")",
Args: []ir.FilterExpr{
{
- Line: 782,
+ Line: 770,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"err\"].Type.Implements(\"error\")",
Value: "err",
- Args: []ir.FilterExpr{{Line: 782, Op: ir.FilterStringOp, Src: "\"error\"", Value: "error"}},
+ Args: []ir.FilterExpr{{Line: 770, Op: ir.FilterStringOp, Src: "\"error\"", Value: "error"}},
},
{
- Line: 782,
+ Line: 770,
Op: ir.FilterVarTypeImplementsOp,
Src: "m[\"err2\"].Type.Implements(\"error\")",
Value: "err2",
- Args: []ir.FilterExpr{{Line: 782, Op: ir.FilterStringOp, Src: "\"error\"", Value: "error"}},
+ Args: []ir.FilterExpr{{Line: 770, Op: ir.FilterStringOp, Src: "\"error\"", Value: "error"}},
},
},
},
{
- Line: 783,
+ Line: 771,
Op: ir.FilterNeqOp,
Src: "m[\"err\"].Text != m[\"err2\"].Text",
Args: []ir.FilterExpr{
- {Line: 783, Op: ir.FilterVarTextOp, Src: "m[\"err\"].Text", Value: "err"},
- {Line: 783, Op: ir.FilterVarTextOp, Src: "m[\"err2\"].Text", Value: "err2"},
+ {Line: 771, Op: ir.FilterVarTextOp, Src: "m[\"err\"].Text", Value: "err"},
+ {Line: 771, Op: ir.FilterVarTextOp, Src: "m[\"err2\"].Text", Value: "err2"},
},
},
},
@@ -2525,108 +2484,34 @@ var PrecompiledRules = &ir.File{
}},
},
{
- Line: 792,
- Name: "sloppyTestFuncName",
+ Line: 780,
+ Name: "badSyncOnceFunc",
MatcherName: "m",
DocTags: []string{"diagnostic", "experimental"},
- DocSummary: "Detects unsupported test and benchmark funcs",
- DocBefore: "func TessstUnit(t *testing.T)",
- DocAfter: "func TestUnit(t *testing.T)",
+ DocSummary: "Detects bad usage of sync.OnceFunc",
+ DocBefore: "sync.OnceFunc(foo)()",
+ DocAfter: "fooOnce := sync.OnceFunc(foo); ...; fooOnce()",
Rules: []ir.Rule{
{
- Line: 793,
- SyntaxPatterns: []ir.PatternString{{Line: 793, Value: "func $test($_ *testing.T) { $*_ }"}},
- ReportTemplate: "function $test should be of form TestXXX(t *testing.T)",
+ Line: 781,
+ SyntaxPatterns: []ir.PatternString{{Line: 781, Value: "$*_; sync.OnceFunc($x); $*_;"}},
+ ReportTemplate: "possible sync.OnceFunc misuse, sync.OnceFunc($x) result is not used",
WhereExpr: ir.FilterExpr{
- Line: 794,
- Op: ir.FilterAndOp,
- Src: "!m[\"test\"].Text.Matches(\"Test.*\") &&\n\t!m[\"test\"].Text.Matches(\"test.*\")",
- Args: []ir.FilterExpr{
- {
- Line: 794,
- Op: ir.FilterNotOp,
- Src: "!m[\"test\"].Text.Matches(\"Test.*\")",
- Args: []ir.FilterExpr{{
- Line: 794,
- Op: ir.FilterVarTextMatchesOp,
- Src: "m[\"test\"].Text.Matches(\"Test.*\")",
- Value: "test",
- Args: []ir.FilterExpr{{Line: 794, Op: ir.FilterStringOp, Src: "\"Test.*\"", Value: "Test.*"}},
- }},
- },
- {
- Line: 795,
- Op: ir.FilterNotOp,
- Src: "!m[\"test\"].Text.Matches(\"test.*\")",
- Args: []ir.FilterExpr{{
- Line: 795,
- Op: ir.FilterVarTextMatchesOp,
- Src: "m[\"test\"].Text.Matches(\"test.*\")",
- Value: "test",
- Args: []ir.FilterExpr{{Line: 795, Op: ir.FilterStringOp, Src: "\"test.*\"", Value: "test.*"}},
- }},
- },
- },
- },
- },
- {
- Line: 798,
- SyntaxPatterns: []ir.PatternString{{Line: 798, Value: "func $bench($_ *testing.B) { $*_ }"}},
- ReportTemplate: "function $bench should be of form BenchmarkXXX(b *testing.B)",
- WhereExpr: ir.FilterExpr{
- Line: 799,
- Op: ir.FilterAndOp,
- Src: "!m[\"bench\"].Text.Matches(\"Benchmark.*\") &&\n\t!m[\"bench\"].Text.Matches(\"bench.*\")",
- Args: []ir.FilterExpr{
- {
- Line: 799,
- Op: ir.FilterNotOp,
- Src: "!m[\"bench\"].Text.Matches(\"Benchmark.*\")",
- Args: []ir.FilterExpr{{
- Line: 799,
- Op: ir.FilterVarTextMatchesOp,
- Src: "m[\"bench\"].Text.Matches(\"Benchmark.*\")",
- Value: "bench",
- Args: []ir.FilterExpr{{Line: 799, Op: ir.FilterStringOp, Src: "\"Benchmark.*\"", Value: "Benchmark.*"}},
- }},
- },
- {
- Line: 800,
- Op: ir.FilterNotOp,
- Src: "!m[\"bench\"].Text.Matches(\"bench.*\")",
- Args: []ir.FilterExpr{{
- Line: 800,
- Op: ir.FilterVarTextMatchesOp,
- Src: "m[\"bench\"].Text.Matches(\"bench.*\")",
- Value: "bench",
- Args: []ir.FilterExpr{{Line: 800, Op: ir.FilterStringOp, Src: "\"bench.*\"", Value: "bench.*"}},
- }},
- },
- },
- },
- },
- {
- Line: 803,
- SyntaxPatterns: []ir.PatternString{{Line: 803, Value: "func $test($_ *testing.T) { $*_ }"}},
- ReportTemplate: "function $test looks like a test helper, consider to change 1st param to 'tb testing.TB'",
- WhereExpr: ir.FilterExpr{
- Line: 804,
- Op: ir.FilterVarTextMatchesOp,
- Src: "m[\"test\"].Text.Matches(\"^test.*\")",
- Value: "test",
- Args: []ir.FilterExpr{{Line: 804, Op: ir.FilterStringOp, Src: "\"^test.*\"", Value: "^test.*"}},
+ Line: 783,
+ Op: ir.FilterGoVersionGreaterEqThanOp,
+ Src: "m.GoVersion().GreaterEqThan(\"1.21\")",
+ Value: "1.21",
},
},
{
- Line: 807,
- SyntaxPatterns: []ir.PatternString{{Line: 807, Value: "func $bench($_ *testing.B) { $*_ }"}},
- ReportTemplate: "function $bench looks like a benchmark helper, consider to change 1st param to 'tb testing.TB'",
+ Line: 785,
+ SyntaxPatterns: []ir.PatternString{{Line: 785, Value: "sync.OnceFunc($x)()"}},
+ ReportTemplate: "possible sync.OnceFunc misuse, consider to assign sync.OnceFunc($x) to a variable",
WhereExpr: ir.FilterExpr{
- Line: 808,
- Op: ir.FilterVarTextMatchesOp,
- Src: "m[\"bench\"].Text.Matches(\"^bench(mark)?.*\")",
- Value: "bench",
- Args: []ir.FilterExpr{{Line: 808, Op: ir.FilterStringOp, Src: "\"^bench(mark)?.*\"", Value: "^bench(mark)?.*"}},
+ Line: 787,
+ Op: ir.FilterGoVersionGreaterEqThanOp,
+ Src: "m.GoVersion().GreaterEqThan(\"1.21\")",
+ Value: "1.21",
},
},
},
diff --git a/vendor/github.com/go-critic/go-critic/checkers/typeUnparen_checker.go b/vendor/github.com/go-critic/go-critic/checkers/typeUnparen_checker.go
index d270268bd..e2e225ebf 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/typeUnparen_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/typeUnparen_checker.go
@@ -14,7 +14,7 @@ func init() {
var info linter.CheckerInfo
info.Name = "typeUnparen"
info.Tags = []string{linter.StyleTag, linter.OpinionatedTag}
- info.Summary = "Detects unneded parenthesis inside type expressions and suggests to remove them"
+ info.Summary = "Detects unneeded parenthesis inside type expressions and suggests to remove them"
info.Before = `type foo [](func([](func())))`
info.After = `type foo []func([]func())`
diff --git a/vendor/github.com/go-critic/go-critic/checkers/unlambda_checker.go b/vendor/github.com/go-critic/go-critic/checkers/unlambda_checker.go
index bcfe5a0c4..0401bf5d3 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/unlambda_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/unlambda_checker.go
@@ -91,7 +91,7 @@ func (c *unlambdaChecker) VisitExpr(x ast.Expr) {
}
}
- if len(result.Args) == n {
+ if c.lenArgs(result.Args) == n {
c.warn(fn, callable)
}
}
@@ -99,3 +99,20 @@ func (c *unlambdaChecker) VisitExpr(x ast.Expr) {
func (c *unlambdaChecker) warn(cause ast.Node, suggestion string) {
c.ctx.Warn(cause, "replace `%s` with `%s`", cause, suggestion)
}
+
+func (c *unlambdaChecker) lenArgs(args []ast.Expr) int {
+ lenArgs := len(args)
+
+ for _, arg := range args {
+ callExp, ok := arg.(*ast.CallExpr)
+ if !ok {
+ continue
+ }
+
+ // Don't count function call. only args.
+ lenArgs--
+ lenArgs += c.lenArgs(callExp.Args)
+ }
+
+ return lenArgs
+}
diff --git a/vendor/github.com/go-critic/go-critic/checkers/unnecessaryDefer_checker.go b/vendor/github.com/go-critic/go-critic/checkers/unnecessaryDefer_checker.go
index 4358ab171..4c1ed41f6 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/unnecessaryDefer_checker.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/unnecessaryDefer_checker.go
@@ -37,7 +37,7 @@ type unnecessaryDeferChecker struct {
// Visit implements the ast.Visitor. This visitor keeps track of the block
// statement belongs to a function or any other block. If the block is not a
// function and ends with a defer statement that should be OK since it's
-// defering the outer function.
+// deferring the outer function.
func (c *unnecessaryDeferChecker) Visit(node ast.Node) ast.Visitor {
switch n := node.(type) {
case *ast.FuncDecl, *ast.FuncLit:
diff --git a/vendor/github.com/go-critic/go-critic/checkers/utils.go b/vendor/github.com/go-critic/go-critic/checkers/utils.go
index e9123352d..4757bbf5f 100644
--- a/vendor/github.com/go-critic/go-critic/checkers/utils.go
+++ b/vendor/github.com/go-critic/go-critic/checkers/utils.go
@@ -260,7 +260,7 @@ func isUnitTestFunc(ctx *linter.CheckerContext, fn *ast.FuncDecl) bool {
return false
}
-// qualifiedName returns called expr fully-quallified name.
+// qualifiedName returns called expr fully-qualified name.
//
// It works for simple identifiers like f => "f" and identifiers
// from other package like pkg.f => "pkg.f".