diff --git a/internal/analyzers/noliteral/linter.go b/internal/analyzers/noliteral/linter.go index aa453b8..107613d 100644 --- a/internal/analyzers/noliteral/linter.go +++ b/internal/analyzers/noliteral/linter.go @@ -57,7 +57,7 @@ func run(pass *analysis.Pass) (interface{}, error) { } 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 } diff --git a/internal/analyzers/use-strconv/linter.go b/internal/analyzers/use-strconv/linter.go index fe6ca1f..304d822 100644 --- a/internal/analyzers/use-strconv/linter.go +++ b/internal/analyzers/use-strconv/linter.go @@ -71,7 +71,7 @@ func run(pass *analysis.Pass) (interface{}, error) { stringLiteral, ok := expr.Args[0].(*ast.BasicLit) - if !ok { + if !ok || astutils.HasNoLintComment(pass, expr.Pos()) { return true } diff --git a/pkg/ast-utils/ast.go b/pkg/ast-utils/ast.go index fcb379e..df22a59 100644 --- a/pkg/ast-utils/ast.go +++ b/pkg/ast-utils/ast.go @@ -5,6 +5,8 @@ import ( "go/token" "strings" "sync" + + "golang.org/x/tools/go/analysis" ) type aliasCacheKey struct { @@ -94,3 +96,16 @@ func GetPackageName(expr ast.Expr) string { } 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 +}