Skip to content

Commit

Permalink
Check all arguments, fixes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-muehle committed May 25, 2021
1 parent 98ad5e9 commit c588e97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 3 additions & 4 deletions checks/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 12 additions & 0 deletions testdata/src/argument/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit c588e97

Please sign in to comment.