Skip to content

Commit edab8b3

Browse files
committed
Skip FuncLit for newline after block
1 parent a911643 commit edab8b3

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

testdata/src/with_config/newline_after_block/blockstatements.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,22 @@ func typeSwitchWithNewline() {
317317

318318
fmt.Println("after type switch")
319319
}
320+
321+
func funcLiteralInvoked() {
322+
err := func() error {
323+
return nil
324+
}()
325+
if err != nil {
326+
panic(err)
327+
}
328+
}
329+
330+
func funcLiteralAssigned() {
331+
someFn := func() {
332+
_ = 1
333+
}
334+
anotherVar := 1
335+
336+
_ = someFn
337+
_ = anotherVar
338+
}

testdata/src/with_config/newline_after_block/blockstatements.go.golden

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,22 @@ func typeSwitchWithNewline() {
340340

341341
fmt.Println("after type switch")
342342
}
343+
344+
func funcLiteralInvoked() {
345+
err := func() error {
346+
return nil
347+
}()
348+
if err != nil {
349+
panic(err)
350+
}
351+
}
352+
353+
func funcLiteralAssigned() {
354+
someFn := func() {
355+
_ = 1
356+
}
357+
anotherVar := 1
358+
359+
_ = someFn
360+
_ = anotherVar
361+
}

wsl.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,14 @@ func (w *WSL) checkStmt(stmt ast.Stmt, cursor *Cursor) {
127127
}
128128
}
129129

130+
//nolint:unparam // False positive on `cursor`
130131
func (w *WSL) checkExpr(expr ast.Expr, cursor *Cursor) {
131132
// This switch traverses all possible subexpressions in search
132133
// of anonymous functions, no matter how unlikely or perhaps even
133134
// semantically impossible it is.
134135
switch s := expr.(type) {
135136
case *ast.FuncLit:
136-
w.checkBlock(s.Body, cursor)
137+
w.checkBlock(s.Body, NewCursor([]ast.Stmt{}))
137138
case *ast.CallExpr:
138139
w.checkExpr(s.Fun, cursor)
139140

0 commit comments

Comments
 (0)