Skip to content

Commit 2c8844f

Browse files
authored
Make append check work isolated, update check type for append (#181)
1 parent a90e48f commit 2c8844f

File tree

6 files changed

+32
-4
lines changed

6 files changed

+32
-4
lines changed

testdata/src/default_config/assign/assign.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func strictAppend() {
2929
x := "c"
3030
s = append(s, x)
3131
y := "e"
32-
s = append(s, "d") // want `missing whitespace above this line \(no shared variables above assign\)`
32+
s = append(s, "d") // want `missing whitespace above this line \(no shared variables above append\)`
3333
s = append(s, y)
3434
}
3535

testdata/src/default_config/assign/assign.go.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func strictAppend() {
3030
s = append(s, x)
3131
y := "e"
3232

33-
s = append(s, "d") // want `missing whitespace above this line \(no shared variables above assign\)`
33+
s = append(s, "d") // want `missing whitespace above this line \(no shared variables above append\)`
3434
s = append(s, y)
3535
}
3636

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package testpkg
2+
3+
func fn1(s []string) {
4+
a := "a"
5+
s = append(s, a)
6+
7+
x := 1
8+
s = append(s, "s") // want `missing whitespace above this line \(no shared variables above append\)`
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package testpkg
2+
3+
func fn1(s []string) {
4+
a := "a"
5+
s = append(s, a)
6+
7+
x := 1
8+
9+
s = append(s, "s") // want `missing whitespace above this line \(no shared variables above append\)`
10+
}
11+

wsl.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ func (w *WSL) checkAssign(stmt *ast.AssignStmt, cursor *Cursor) {
402402
for _, expr := range stmt.Rhs {
403403
w.checkExpr(expr, cursor)
404404
}
405+
406+
w.checkAppend(stmt, cursor)
405407
}()
406408

407409
if _, ok := w.config.Checks[CheckAssign]; !ok {
@@ -411,7 +413,6 @@ func (w *WSL) checkAssign(stmt *ast.AssignStmt, cursor *Cursor) {
411413
cursor.SetChecker(CheckAssign)
412414

413415
w.checkCuddlingWithoutIntersection(stmt, cursor)
414-
w.checkAppend(stmt, cursor)
415416
}
416417

417418
func (w *WSL) checkAppend(stmt *ast.AssignStmt, cursor *Cursor) {
@@ -444,7 +445,7 @@ func (w *WSL) checkAppend(stmt *ast.AssignStmt, cursor *Cursor) {
444445
}
445446

446447
if !hasIntersection(appendNode, previousNode) {
447-
w.addErrorNoIntersection(stmt.Pos(), cursor.checkType)
448+
w.addErrorNoIntersection(stmt.Pos(), CheckAppend)
448449
}
449450
}
450451

wsl_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ func TestWithConfig(t *testing.T) {
9393
config.Checks.Add(CheckErr)
9494
},
9595
},
96+
{
97+
subdir: "append_only",
98+
configFn: func(config *Configuration) {
99+
config.Checks = NoChecks()
100+
config.Checks.Add(CheckAppend)
101+
},
102+
},
96103
} {
97104
t.Run(tc.subdir, func(t *testing.T) {
98105
config := NewConfig()

0 commit comments

Comments
 (0)