Skip to content

Commit

Permalink
Allows identifying Go built-in functions such as 'make()`
Browse files Browse the repository at this point in the history
  • Loading branch information
gdavison committed Oct 1, 2021
1 parent ce948a3 commit d5db99f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ The ```-ignored-numbers``` option let's you define a comma separated list of num
For example: `-ignored-numbers=1000,10_000,3.14159264`

The ```-ignored-functions``` option let's you define a comma separated list of function name regexp patterns to exclude.
For example: `-ignored-functions=math.*,http.StatusText`
For example: `-ignored-functions=math.*,http.StatusText,make`

The ```-ignored-files``` option let's you define a comma separated list of filename regexp patterns to exclude.
For example: `-ignored-files=magic_.*.go,.*_numbers.go`
Expand Down
2 changes: 1 addition & 1 deletion analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestCanIgnoreFunctions(t *testing.T) {
options.String("checks", "argument", "")
options.String("excludes", "", "")
options.String("ignored-files", "", "")
options.String("ignored-functions", "math.*", "")
options.String("ignored-functions", "math.*,make", "")
options.String("ignored-numbers", "", "")

analyzer := Analyzer
Expand Down
4 changes: 4 additions & 0 deletions checks/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func (a *ArgumentAnalyzer) checkCallExpr(expr *ast.CallExpr) {
return
}
}
case *ast.Ident:
if a.config.IsIgnoredFunction(f.Name) {
return
}
}

for i, arg := range expr.Args {
Expand Down
6 changes: 6 additions & 0 deletions testdata/src/ignored/functions/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ func example3() {
// ignored via configuration
math.Acos(1.5)
}

func example4() {
// ignored via configuration
a := make([]int, 0, 10)
a[0] = 1
}

0 comments on commit d5db99f

Please sign in to comment.