Repository: bombsimon/wsl
Pull request #28 (2019-10-09 08:12:18)

Add support for SliceExpr
Supporting `[start:end]` in slices.

coveralls: ## Pull Request Test Coverage Report for [Build 91](https://coveralls.io/builds/26200632)

* **4** of **4**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.1%**) to **86.182%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/26200632/badge)](https://coveralls.io/builds/26200632) |
| :-- | --: |
| Change from base [Build 85](https://coveralls.io/builds/26199838): |  0.1% |
| Covered Lines: | 948 |
| Relevant Lines: | 1100 |

---
##### 💛  - [Coveralls](https://coveralls.io)

coveralls: ## Pull Request Test Coverage Report for [Build 91](https://coveralls.io/builds/26200632)

* **4** of **4**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.1%**) to **86.182%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/26200632/badge)](https://coveralls.io/builds/26200632) |
| :-- | --: |
| Change from base [Build 85](https://coveralls.io/builds/26199838): |  0.1% |
| Covered Lines: | 948 |
| Relevant Lines: | 1100 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/wsl.go b/wsl.go
index ba6119e..ff5798d 100644
--- a/wsl.go
+++ b/wsl.go
@@ -661,6 +661,10 @@ func (p *Processor) findRHS(node ast.Node) []string {
 	case *ast.IndexExpr:
 		rhs = append(rhs, p.findRHS(t.Index)...)
 		rhs = append(rhs, p.findRHS(t.X)...)
+	case *ast.SliceExpr:
+		rhs = append(rhs, p.findRHS(t.X)...)
+		rhs = append(rhs, p.findRHS(t.Low)...)
+		rhs = append(rhs, p.findRHS(t.High)...)
 	default:
 		if x, ok := maybeX(t); ok {
 			return p.findRHS(x)
@@ -676,7 +680,7 @@ func (p *Processor) findRHS(node ast.Node) []string {
 // if it exists. If the node doesn't have an X field nil and false is returned.
 // Known fields with X that are handled:
 // IndexExpr, ExprStmt, SelectorExpr, StarExpr, ParentExpr, TypeAssertExpr,
-// RangeStmt, UnaryExpr, ParenExpr, SLiceExpr, IncDecStmt.
+// RangeStmt, UnaryExpr, ParenExpr, SliceExpr, IncDecStmt.
 func maybeX(node interface{}) (ast.Node, bool) {
 	maybeHasX := reflect.Indirect(reflect.ValueOf(node)).FieldByName("X")
 	if !maybeHasX.IsValid() {


Test patch:
diff --git a/wsl_test.go b/wsl_test.go
index 7616393..557e849 100644
--- a/wsl_test.go
+++ b/wsl_test.go
@@ -984,6 +984,36 @@ func TestShouldAddEmptyLines(t *testing.T) {
 				}
 			}`),
 		},
+		{
+			description: "splice slice, concat key",
+			code: []byte(`package main
+
+			func main() {
+				start := 0
+				if v := aSlice[start:3]; v {
+					fmt.Println("")
+				}
+
+				someKey := "str"
+				if v, ok := someMap[obtain(someKey)+"str"]; ok {
+					fmt.Println("Hey there")
+				}
+
+				end := 10
+				if v := arr[3:notEnd]; !v {
+					// Error
+				}
+
+				notKey := "str"
+				if v, ok := someMap[someKey]; ok {
+					// Error
+				}
+			}`),
+			expectedErrorStrings: []string{
+				"if statements should only be cuddled with assignments used in the if statement itself",
+				"if statements should only be cuddled with assignments used in the if statement itself",
+			},
+		},
 	}
 
 	for _, tc := range cases {