Repository: bombsimon/wsl (go)

Issue:
Support multiple go-statements
I think it should be allowed to cuddle multiple go statements if they're on a single line like this:

```go
t1 := CreateT()
t2 := CreateT()
t2 := CreateT()

go t1.Func()
go t2.Func()
go t3.Func()
```

Today the alternatives would be:

```go
t1 := CreateT()
t2 := CreateT()
t2 := CreateT()

go t1.Func()

go t2.Func()

go t3.Func()
```

Or

```
t1 := CreateT()
go t1.Func()

t2 := CreateT()
go t2.Func()

t2 := CreateT()
go t3.Func()
```

But the last one is not reasonable if we have to do mor things with `tn`, e.g.

```go
t1 := CreateT()
t1.SetX(1)
t1.SetY(2)

go t1.Func()
```

Pull request description:
Support multiple go statements, fix IncDec bug
Resolves #42, now supports:

```go
go func1()
go func2()
go func3()
```

Also fixes an unreported bug where variables used as increase or decrease statement wasn't considered. This was not, but is now, supported:

```go
counter := 0
if [expr] {
    counter++
}
```

Patch:
diff --git a/wsl.go b/wsl.go
index 8bb9647..8699bbc 100644
--- a/wsl.go
+++ b/wsl.go
@@ -477,6 +477,10 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
 				}
 			}
 		case *ast.GoStmt:
+			if _, ok := previousStatement.(*ast.GoStmt); ok {
+				continue
+			}
+
 			if moreThanOneStatementAbove() {
 				p.addError(t.Pos(), "only one cuddle assignment allowed before go statement")
 
@@ -599,9 +603,10 @@ func (p *Processor) findLHS(node ast.Node) []string {
 		*ast.ReturnStmt, *ast.GoStmt, *ast.CaseClause,
 		*ast.CommClause, *ast.CallExpr, *ast.UnaryExpr,
 		*ast.BranchStmt, *ast.TypeSpec, *ast.ChanType,
-		*ast.DeferStmt, *ast.TypeAssertExpr, *ast.IncDecStmt,
-		*ast.RangeStmt:
-		// Nothing to add to LHS
+		*ast.DeferStmt, *ast.TypeAssertExpr, *ast.RangeStmt:
+	// Nothing to add to LHS
+	case *ast.IncDecStmt:
+		return p.findLHS(t.X)
 	case *ast.Ident:
 		return []string{t.Name}
 	case *ast.AssignStmt:


Test patch:
diff --git a/wsl_test.go b/wsl_test.go
index 5507d74..726494d 100644
--- a/wsl_test.go
+++ b/wsl_test.go
@@ -1082,6 +1082,61 @@ func TestShouldAddEmptyLines(t *testing.T) {
 				defer resp.Body.Close()
 			}`),
 		},
+		{
+			description: "multiple go statements can be cuddled",
+			code: []byte(`package main
+
+			func main() {
+				t1 := NewT()
+				t2 := NewT()
+				t3 := NewT()
+
+				go t1()
+				go t2()
+				go t3()
+
+				multiCuddle1 := NewT()
+				multiCuddle2 := NewT()
+				go multiCuddle2()
+
+				multiCuddle3 := NeT()
+				go multiCuddle1()
+
+				t4 := NewT()
+				t5 := NewT()
+				go t5()
+				go t4()
+			}`),
+			expectedErrorStrings: []string{
+				"only one cuddle assignment allowed before go statement",
+				"go statements can only invoke functions assigned on line above",
+				"only one cuddle assignment allowed before go statement",
+			},
+		},
+		{
+			description: "boilerplate",
+			code: []byte(`package main
+
+			func main() {
+				counter := 0
+				if somethingTrue {
+					counter++
+				}
+
+				counterTwo := 0
+				if somethingTrue {
+					counterTwo--
+				}
+
+				notCounter := 0
+				if somethingTrue {
+					counter--
+				}
+			}`),
+			expectedErrorStrings: []string{
+				"if statements should only be cuddled with assignments used in the if statement itself",
+			},
+		},
 	}
 
 	for _, tc := range cases {