Skip to content

Commit

Permalink
Fix missing expression cuddle check
Browse files Browse the repository at this point in the history
  • Loading branch information
bombsimon committed Jun 23, 2024
1 parent 1fc4441 commit e598d52
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
13 changes: 13 additions & 0 deletions testdata/src/default_config/generic_handling.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,16 @@ func AnonymousFunc() {
return nil // want "return statements should not be cuddled if block has more than two lines"
}())
}

// Issue #153
func ExpressionForBlock() {
for i := 0; i < 4; i++ {
fmt.Println()
}
Up(3) // want "expressions should not be cuddled with blocks"

if autoheight != 3 {
t.Errorf("height should be 3 but is %d", autoheight)
}
Down(3) // want "expressions should not be cuddled with blocks"
}
15 changes: 15 additions & 0 deletions testdata/src/default_config/generic_handling.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,18 @@ func AnonymousFunc() {
return nil // want "return statements should not be cuddled if block has more than two lines"
}())
}

// Issue #153
func ExpressionForBlock() {
for i := 0; i < 4; i++ {
fmt.Println()
}

Up(3) // want "expressions should not be cuddled with blocks"

if autoheight != 3 {
t.Errorf("height should be 3 but is %d", autoheight)
}

Down(3) // want "expressions should not be cuddled with blocks"
}
2 changes: 1 addition & 1 deletion wsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ func (p *processor) parseBlockStatements(statements []ast.Stmt) {
}

p.addWhitespaceBeforeError(t, reasonExpressionCuddledWithDeclOrRet)
case *ast.IfStmt, *ast.RangeStmt, *ast.SwitchStmt:
case *ast.IfStmt, *ast.RangeStmt, *ast.SwitchStmt, *ast.TypeSwitchStmt, *ast.ForStmt:
p.addWhitespaceBeforeError(t, reasonExpressionCuddledWithBlock)
}

Expand Down

0 comments on commit e598d52

Please sign in to comment.