[] linters: add useStrconv linter #10

Merged
dstepanov-yadro merged 3 commits from achuprov/linters:nofmt into master 2024-09-04 19:51:22 +00:00
3 changed files with 17 additions and 2 deletions
Showing only changes of commit d0450b6301 - Show all commits
internal/analyzers
noliteral
use-strconv
pkg/ast-utils

View file

@ -57,7 +57,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
} }
isLog, _ := astutils.IsTargetMethod(expr.Fun, Config.TargetMethods) isLog, _ := astutils.IsTargetMethod(expr.Fun, Config.TargetMethods)
if !isLog || len(expr.Args) == 0 { if !isLog || len(expr.Args) == 0 || astutils.HasNoLintComment(pass, expr.Pos()) {
return true return true
} }

View file

@ -71,7 +71,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
stringLiteral, ok := expr.Args[0].(*ast.BasicLit) stringLiteral, ok := expr.Args[0].(*ast.BasicLit)
if !ok { if !ok || astutils.HasNoLintComment(pass, expr.Pos()) {
return true return true
} }

View file

@ -5,6 +5,8 @@ import (
"go/token" "go/token"
"strings" "strings"
"sync" "sync"
"golang.org/x/tools/go/analysis"
) )
type aliasCacheKey struct { type aliasCacheKey struct {
@ -94,3 +96,16 @@ func GetPackageName(expr ast.Expr) string {
} }
return "" return ""
} }
func HasNoLintComment(pass *analysis.Pass, pos token.Pos) bool {
for _, commentGroup := range pass.Files[0].Comments {
if commentGroup.End() < pos {
for _, comment := range commentGroup.List {
if strings.Contains(comment.Text, "nolint") {
return true
}
}
}
}
return false
}