From c588e97417345a8d6cde3d418988f18e8c94207b Mon Sep 17 00:00:00 2001 From: Tommy Muehle Date: Tue, 25 May 2021 22:52:06 +0200 Subject: [PATCH] Check all arguments, fixes #25 --- checks/argument.go | 7 +++---- testdata/src/argument/argument.go | 12 ++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/checks/argument.go b/checks/argument.go index a0a86e8..df6ad67 100644 --- a/checks/argument.go +++ b/checks/argument.go @@ -86,10 +86,9 @@ func (a *ArgumentAnalyzer) checkCallExpr(expr *ast.CallExpr) { if i == 0 { a.pass.Reportf(x.Pos(), reportMsg, x.Value, ArgumentCheck) } else { - // Otherwise check the previous element type - switch expr.Args[i-1].(type) { - case *ast.ChanType: - // When it's not a simple buffered channel, report it + // Otherwise check all args + switch expr.Args[i].(type) { + case *ast.BasicLit: if a.isMagicNumber(x) { a.pass.Reportf(x.Pos(), reportMsg, x.Value, ArgumentCheck) } diff --git a/testdata/src/argument/argument.go b/testdata/src/argument/argument.go index 5aa2926..8b86ff4 100644 --- a/testdata/src/argument/argument.go +++ b/testdata/src/argument/argument.go @@ -80,3 +80,15 @@ func example10() { wg.Done() }() } + +func foobar(a, b int) {} + +func example11() { + foobar(0, 3) // want "Magic number: 3" +} + +func foobaz(numbers ...int) {} + +func example12() { + foobaz(0, 1, 3, 5, 6) // want "Magic number: 3" "Magic number: 5" "Magic number: 6" +}