[#10] linters: Add support for the nolint comment

Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
Alexander Chuprov 2023-08-17 15:28:14 +03:00
parent a2983f6cb8
commit d0450b6301
3 changed files with 17 additions and 2 deletions

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
}