Skip to content

Commit 19bf57c

Browse files
committed
Don't report type conversions in const block declarations, fixes #22
1 parent e9b14af commit 19bf57c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

checks/argument.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ func (a *ArgumentAnalyzer) Check(n ast.Node) {
4141
case *ast.CallExpr:
4242
a.checkCallExpr(expr)
4343
case *ast.GenDecl:
44-
if expr.Tok == token.CONST {
45-
pos := a.pass.Fset.Position(expr.TokPos)
44+
if expr.Tok != token.CONST {
45+
return
46+
}
47+
48+
for _, x := range expr.Specs {
49+
pos := a.pass.Fset.Position(x.Pos())
4650

4751
mu.Lock()
4852
constantDefinitions[pos.Filename+":"+strconv.Itoa(pos.Line)] = true

testdata/src/argument/argument.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ var MyValue = float32(20) // want "Magic number: 20"
1414

1515
const MyConstantValue = float32(20)
1616

17+
const (
18+
FooBlockTypeConversion = int64(512)
19+
BarBlockTypeConversion = uint8(2)
20+
)
21+
1722
func example() {
1823
math.Abs(9.5) // want "Magic number: 9.5"
1924
}

0 commit comments

Comments
 (0)