Repository: mgechev/revive (go)

Issue:
`chan struct{}` triggers nested-structs error
**Describe the bug**
`chan struct{}` triggers the nested-structs error.

**Expected behavior**
I expected this use case to be ignored.

**Desktop (please complete the following information):**
 - OS: macOS Monterey
 - Version of Go: 1.19

**Additional context**
I'm presuming this is a false positive bug and there's no idiomatic go way to work around it (apologies if there is and I wasn't aware).


Pull request description:
fix #744: `chan struct{}` triggers nested-structs error
Closes #744 


Patch:
diff --git a/rule/nested-structs.go b/rule/nested-structs.go
index b4f7352..968511f 100644
--- a/rule/nested-structs.go
+++ b/rule/nested-structs.go
@@ -43,6 +43,11 @@ func (l *lintNestedStructs) Visit(n ast.Node) ast.Visitor {
 		}
 		return nil
 	case *ast.Field:
+		_, isChannelField := v.Type.(*ast.ChanType)
+		if isChannelField {
+			return nil
+		}
+
 		filter := func(n ast.Node) bool {
 			switch n.(type) {
 			case *ast.StructType:


Test patch:
diff --git a/testdata/nested-structs.go b/testdata/nested-structs.go
index 7e5abaf..8823d65 100644
--- a/testdata/nested-structs.go
+++ b/testdata/nested-structs.go
@@ -35,3 +35,8 @@ func fred() interface{} {
 type Bad struct {
 	Field []struct{} // MATCH /no nested structs are allowed/
 }
+
+// issue744
+type issue744 struct {
+	c chan struct{}
+}