Skip to content

Commit

Permalink
Don't report type conversions in const block declarations, fixes #22
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-muehle committed Apr 16, 2021
1 parent e9b14af commit 19bf57c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions checks/argument.go
Expand Up @@ -41,8 +41,12 @@ func (a *ArgumentAnalyzer) Check(n ast.Node) {
case *ast.CallExpr:
a.checkCallExpr(expr)
case *ast.GenDecl:
if expr.Tok == token.CONST {
pos := a.pass.Fset.Position(expr.TokPos)
if expr.Tok != token.CONST {
return
}

for _, x := range expr.Specs {
pos := a.pass.Fset.Position(x.Pos())

mu.Lock()
constantDefinitions[pos.Filename+":"+strconv.Itoa(pos.Line)] = true
Expand Down
5 changes: 5 additions & 0 deletions testdata/src/argument/argument.go
Expand Up @@ -14,6 +14,11 @@ var MyValue = float32(20) // want "Magic number: 20"

const MyConstantValue = float32(20)

const (
FooBlockTypeConversion = int64(512)
BarBlockTypeConversion = uint8(2)
)

func example() {
math.Abs(9.5) // want "Magic number: 9.5"
}
Expand Down

0 comments on commit 19bf57c

Please sign in to comment.