Skip to content

Commit f391143

Browse files
authored
Merge pull request #29 from gdavison/ignore-builtin-functions
Support ignoring Go built-in functions when excluding functions
2 parents ce948a3 + d5db99f commit f391143

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ The ```-ignored-numbers``` option let's you define a comma separated list of num
118118
For example: `-ignored-numbers=1000,10_000,3.14159264`
119119

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

123123
The ```-ignored-files``` option let's you define a comma separated list of filename regexp patterns to exclude.
124124
For example: `-ignored-files=magic_.*.go,.*_numbers.go`

analyzer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestCanIgnoreFunctions(t *testing.T) {
4444
options.String("checks", "argument", "")
4545
options.String("excludes", "", "")
4646
options.String("ignored-files", "", "")
47-
options.String("ignored-functions", "math.*", "")
47+
options.String("ignored-functions", "math.*,make", "")
4848
options.String("ignored-numbers", "", "")
4949

5050
analyzer := Analyzer

checks/argument.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ func (a *ArgumentAnalyzer) checkCallExpr(expr *ast.CallExpr) {
7474
return
7575
}
7676
}
77+
case *ast.Ident:
78+
if a.config.IsIgnoredFunction(f.Name) {
79+
return
80+
}
7781
}
7882

7983
for i, arg := range expr.Args {

testdata/src/ignored/functions/functions.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ func example3() {
1818
// ignored via configuration
1919
math.Acos(1.5)
2020
}
21+
22+
func example4() {
23+
// ignored via configuration
24+
a := make([]int, 0, 10)
25+
a[0] = 1
26+
}

0 commit comments

Comments
 (0)