From d5db99f5fd6172c439297d6122b2dad557693fa4 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Thu, 30 Sep 2021 17:42:51 -0700 Subject: [PATCH] Allows identifying Go built-in functions such as 'make()` --- README.md | 2 +- analyzer_test.go | 2 +- checks/argument.go | 4 ++++ testdata/src/ignored/functions/functions.go | 6 ++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6e3a555..a29f266 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/analyzer_test.go b/analyzer_test.go index c359d94..c376ffd 100644 --- a/analyzer_test.go +++ b/analyzer_test.go @@ -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 diff --git a/checks/argument.go b/checks/argument.go index df6ad67..5d880f0 100644 --- a/checks/argument.go +++ b/checks/argument.go @@ -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 { diff --git a/testdata/src/ignored/functions/functions.go b/testdata/src/ignored/functions/functions.go index 6163ee9..80bdd74 100644 --- a/testdata/src/ignored/functions/functions.go +++ b/testdata/src/ignored/functions/functions.go @@ -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 +}