Repository: bombsimon/wsl (go)

Issue:
`++`/`--` should be treated as an assignment
Consider this somewhere in the code:
```
	count++
	isSet = true
```
I got this:
```
assignments should only be cuddled with other assignments (wsl)
                        isSet = true
```
but in fact  the count++ is an assignment as well (count = count + 1)

Pull request:
Treat `IncDecStmt` as `AssignStmt`
`++` and `--` operator are very similar to `x = x + 1` so we make it simple and just treat it as an assignment.

Closes #120

Patch:
diff --git a/wsl.go b/wsl.go
index 636e35b..cfeecc2 100644
--- a/wsl.go
+++ b/wsl.go
@@ -508,7 +508,8 @@ func (p *processor) parseBlockStatements(statements []ast.Stmt) {
 				continue
 			}
 
-			if _, ok := previousStatement.(*ast.AssignStmt); ok {
+			switch previousStatement.(type) {
+			case *ast.AssignStmt, *ast.IncDecStmt:
 				continue
 			}
 
@@ -533,6 +534,14 @@ func (p *processor) parseBlockStatements(statements []ast.Stmt) {
 			}
 
 			p.addWhitespaceBeforeError(t, reasonAssignsCuddleAssign)
+		case *ast.IncDecStmt:
+			switch previousStatement.(type) {
+			case *ast.AssignStmt, *ast.IncDecStmt:
+				continue
+			}
+
+			p.addWhitespaceBeforeError(t, reasonAssignsCuddleAssign)
+
 		case *ast.DeclStmt:
 			if !p.config.AllowCuddleDeclaration {
 				p.addWhitespaceBeforeError(t, reasonNeverCuddleDeclare)


Test patch:
diff --git a/testdata/src/default_config/generic_handling.go b/testdata/src/default_config/generic_handling.go
index f09ce52..02f7523 100644
--- a/testdata/src/default_config/generic_handling.go
+++ b/testdata/src/default_config/generic_handling.go
@@ -557,3 +557,19 @@ func OnlyCheckTwoLinesAboveIfAssignment() {
 		return result, err
 	}
 }
+
+func IncrementDecrement() {
+	a := 1
+	a++
+	a--
+	b := 2
+
+	if true {
+		b--
+	}
+	b++ // want "assignments should only be cuddled with other assignments"
+
+	go func() {}()
+	b++            // want "assignments should only be cuddled with other assignments"
+	go func() {}() // want "only one cuddle assignment allowed before go statement"
+}
diff --git a/testdata/src/default_config/generic_handling.go.golden b/testdata/src/default_config/generic_handling.go.golden
index 91ffc5a..254013d 100644
--- a/testdata/src/default_config/generic_handling.go.golden
+++ b/testdata/src/default_config/generic_handling.go.golden
@@ -597,3 +597,22 @@ func OnlyCheckTwoLinesAboveIfAssignment() {
 		return result, err
 	}
 }
+
+func IncrementDecrement() {
+	a := 1
+	a++
+	a--
+	b := 2
+
+	if true {
+		b--
+	}
+
+	b++ // want "assignments should only be cuddled with other assignments"
+
+	go func() {}()
+
+	b++ // want "assignments should only be cuddled with other assignments"
+
+	go func() {}() // want "only one cuddle assignment allowed before go statement"
+}