forked from TrueCloudLab/linters
[#10] linters: Add support for the nolint comment
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
a2983f6cb8
commit
d0450b6301
3 changed files with 17 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue