Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tommy-muehle/go-mnd
Browse files Browse the repository at this point in the history
# Conflicts:
#	checks/argument.go
  • Loading branch information
tommy-muehle committed Jan 22, 2021
2 parents 9a7adaf + 31b8e70 commit 605e3d8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion checks/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package checks
import (
"go/ast"
"go/token"
"sync"

"golang.org/x/tools/go/analysis"

Expand All @@ -13,6 +14,7 @@ const ArgumentCheck = "argument"

// constantDefinitions is used to save lines (by number) which contain a constant definition.
var constantDefinitions = map[int]bool{}
var mu sync.RWMutex

type ArgumentAnalyzer struct {
config *config.Config
Expand All @@ -39,13 +41,19 @@ func (a *ArgumentAnalyzer) Check(n ast.Node) {
a.checkCallExpr(expr)
case *ast.GenDecl:
if expr.Tok.String() == "const" {
mu.Lock()
constantDefinitions[a.pass.Fset.Position(expr.TokPos).Line] = true
mu.Unlock()
}
}
}

func (a *ArgumentAnalyzer) checkCallExpr(expr *ast.CallExpr) {
if ok := constantDefinitions[a.pass.Fset.Position(expr.Pos()).Line]; ok {
mu.RLock()
ok := constantDefinitions[a.pass.Fset.Position(expr.Pos()).Line]
mu.RUnlock()

if ok {
return
}

Expand Down

0 comments on commit 605e3d8

Please sign in to comment.