Remove check for 0-length make.
While a 0-length make is sometimes done when a user should
have used "var s []int", the current lint check is reported to
cause too many false positives on legitimate uses of 0-length make.
This occurs because there is a semantic difference between
"make([]int, 0)" and "var s []int".
Fixes #234
diff --git a/lint.go b/lint.go
index f98d9b9..ab6433a 100644
--- a/lint.go
+++ b/lint.go
@@ -183,7 +183,6 @@
f.lintErrorStrings()
f.lintReceiverNames()
f.lintIncDec()
- f.lintMake()
f.lintErrorReturn()
f.lintUnexportedReturn()
f.lintTimeNames()
@@ -1273,35 +1272,6 @@
})
}
-// lintMake examines statements that declare and initialize a variable with make.
-// It complains if they are constructing a zero element slice.
-func (f *file) lintMake() {
- f.walk(func(n ast.Node) bool {
- as, ok := n.(*ast.AssignStmt)
- if !ok {
- return true
- }
- // Only want single var := assignment statements.
- if len(as.Lhs) != 1 || as.Tok != token.DEFINE {
- return true
- }
- ce, ok := as.Rhs[0].(*ast.CallExpr)
- if !ok {
- return true
- }
- // Check if ce is make([]T, 0).
- if !isIdent(ce.Fun, "make") || len(ce.Args) != 2 || !isZero(ce.Args[1]) {
- return true
- }
- at, ok := ce.Args[0].(*ast.ArrayType)
- if !ok || at.Len != nil {
- return true
- }
- f.errorf(as, 0.8, category("slice"), `can probably use "var %s %s" instead`, f.render(as.Lhs[0]), f.render(at))
- return true
- })
-}
-
// lintErrorReturn examines function declarations that return an error.
// It complains if the error isn't the last parameter.
func (f *file) lintErrorReturn() {
diff --git a/testdata/make.go b/testdata/make.go
deleted file mode 100644
index eb5362a..0000000
--- a/testdata/make.go
+++ /dev/null
@@ -1,19 +0,0 @@
-// Test for pointless make() calls.
-
-// Package pkg ...
-package pkg
-
-import "net/http"
-
-// T is a test type.
-type T int
-
-var z []T
-
-func f() {
- x := make([]T, 0) // MATCH /var x \[\]T/
- y := make([]http.Request, 0) // MATCH /var y \[\]http\.Request/
- z = make([]T, 0) // ok, because we don't know where z is declared
-
- _, _ = x, y
-}