Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing expression cuddle check #154

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading