Repository: mgechev/revive (go)

Issue:
Request: report "redefinition of the built-in" errors for function related variables
**Is your feature request related to a problem? Please describe.**

Currently, function related variables are not checked by `redefinition of the built-in ...`.
It would be nice if revive reports `redefinition of the built-in ...` errors for function related variables.

For example, revive does not report any errors for the following `main.go` file:
```golang
// This is a package comment
package main

func main() {
}

// 1 param
func foo1(new int) {
	_ = new
}

// 2 result
func foo2() (new int) {
	return
}

// 3 type param
func foo3[new any]() {
}
```

```
❯ revive -set_exit_status main.go

❯ echo $?
0
```

**Describe the solution you'd like**

revive reports `redefinition of the built-in ...` errors for function related variables, so that:

```
❯ revive -set_exit_status main.go
main.go:8:11: redefinition of the built-in function new
main.go:13:14: redefinition of the built-in function new
main.go:18:11: redefinition of the built-in function new

❯ echo $?
1
```

**Describe alternatives you've considered**

NA

**Additional context**

I'm not completely certain, but I believe that by making the following changes, this feature can be implemented.

```diff
diff --git rule/redefines-builtin-id.go rule/redefines-builtin-id.go
index b3ff084..d0870fd 100644
--- rule/redefines-builtin-id.go
+++ rule/redefines-builtin-id.go
@@ -125,6 +125,29 @@ func (w *lintRedefinesBuiltinID) Visit(node ast.Node) ast.Visitor {
 		if ok, bt := w.isBuiltIn(id); ok {
 			w.addFailure(n, fmt.Sprintf("redefinition of the built-in %s %s", bt, id))
 		}
+	case *ast.FuncType:
+		var fields []*ast.Field
+		if n.TypeParams != nil {
+			fields = append(fields, n.TypeParams.List...)
+		}
+		if n.Params != nil {
+			fields = append(fields, n.Params.List...)
+		}
+		if n.Results != nil {
+			fields = append(fields, n.Results.List...)
+		}
+		for _, field := range fields {
+			for _, name := range field.Names {
+				if obj := name.Obj; obj != nil {
+					if obj.Kind == ast.Var || obj.Kind == ast.Typ {
+						id := obj.Name
+						if ok, bt := w.isBuiltIn(id); ok {
+							w.addFailure(name, fmt.Sprintf("redefinition of the built-in %s %s", bt, id))
+						}
+					}
+				}
+			}
+		}
 	case *ast.AssignStmt:
 		for _, e := range n.Lhs {
 			id, ok := e.(*ast.Ident)
```


Pull request description:
check param, result, type param of function in redefines-builtin-id rule
Close #1022 

Currently, function related variables (param, result, and type param) are not checked by `redefines-builtin-id rule`.
It would be nice if revive reports `redefinition of the built-in ...` errors for function related variables.

<!-- ### IMPORTANT ### -->
<!-- Please do not create a Pull Request without creating an issue first.** -->
<!-- If you're fixing a typo or improving the documentation, you may not have to open an issue. -->

<!-- ### CHECKLIST ### -->
<!-- Please, describe in details what's your motivation for this PR -->
<!-- Did you add tests? -->
<!-- Does your code follow the coding style of the rest of the repository? -->
<!-- Does the Travis build passes? -->

<!-- ### FOOTER (OPTIONAL) ### -->
<!-- If you're closing an issue, add "Closes #XXXX" in your comment. This way, the PR will be linked to the issue automatically. -->


Patch:
diff --git a/rule/redefines-builtin-id.go b/rule/redefines-builtin-id.go
index f367ea8..8aaaf03 100644
--- a/rule/redefines-builtin-id.go
+++ b/rule/redefines-builtin-id.go
@@ -145,6 +145,31 @@ func (w *lintRedefinesBuiltinID) Visit(node ast.Node) ast.Visitor {
 		if ok, bt := w.isBuiltIn(id); ok {
 			w.addFailure(n, fmt.Sprintf("redefinition of the built-in %s %s", bt, id))
 		}
+	case *ast.FuncType:
+		var fields []*ast.Field
+		if n.TypeParams != nil {
+			fields = append(fields, n.TypeParams.List...)
+		}
+		if n.Params != nil {
+			fields = append(fields, n.Params.List...)
+		}
+		if n.Results != nil {
+			fields = append(fields, n.Results.List...)
+		}
+		for _, field := range fields {
+			for _, name := range field.Names {
+				obj := name.Obj
+				isTypeOrName := obj != nil && (obj.Kind == ast.Var || obj.Kind == ast.Typ)
+				if !isTypeOrName {
+					continue
+				}
+				
+				id := obj.Name
+				if ok, bt := w.isBuiltIn(id); ok {
+					w.addFailure(name, fmt.Sprintf("redefinition of the built-in %s %s", bt, id))
+				}
+			}
+		}
 	case *ast.AssignStmt:
 		for _, e := range n.Lhs {
 			id, ok := e.(*ast.Ident)


Test patch:
diff --git a/testdata/redefines-builtin-id.go b/testdata/redefines-builtin-id.go
index e5f7c16..2426b10 100644
--- a/testdata/redefines-builtin-id.go
+++ b/testdata/redefines-builtin-id.go
@@ -41,3 +41,14 @@ func foo() {
 	_ = max
 	_ = min
 }
+
+func foo1(new int) { // MATCH /redefinition of the built-in function new/
+	_ = new
+}
+
+func foo2() (new int) { // MATCH /redefinition of the built-in function new/
+	return
+}
+
+func foo3[new any]() { // MATCH /redefinition of the built-in function new/
+}