Skip to content

Commit

Permalink
Merge pull request #29 from gdavison/ignore-builtin-functions
Browse files Browse the repository at this point in the history
Support ignoring Go built-in functions when excluding functions
  • Loading branch information
tommy-muehle committed Nov 8, 2021
2 parents ce948a3 + d5db99f commit f391143
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
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
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
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
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 f391143

Please sign in to comment.