Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ignoring Go built-in functions when excluding functions #29

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 1 addition & 1 deletion analyzer_test.go
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions checks/argument.go
Original file line number Diff line number Diff line change
@@ -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 {
6 changes: 6 additions & 0 deletions testdata/src/ignored/functions/functions.go
Original file line number Diff line number Diff line change
@@ -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
}