Skip to content

Commit

Permalink
Check next block start by case, not colon
Browse files Browse the repository at this point in the history
  • Loading branch information
bombsimon committed Oct 10, 2019
1 parent 57625e9 commit de564df
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions wsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,9 +815,9 @@ func (p *Processor) findLeadingAndTrailingWhitespaces(stmt, nextStatement ast.No

switch n := nextStatement.(type) {
case *ast.CaseClause:
blockEndPos = n.Colon
blockEndPos = n.Case
case *ast.CommClause:
blockEndPos = n.Colon
blockEndPos = n.Case
default:
// We're not at the end of the case?
return
Expand Down
41 changes: 41 additions & 0 deletions wsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,47 @@ func TestShouldAddEmptyLines(t *testing.T) {
"if statements should only be cuddled with assignments used in the if statement itself",
},
},
{
description: "multiline case statements",
code: []byte(`package main
func main() {
switch {
case true,
false:
fmt.Println("ok")
case true ||
false:
fmt.Println("ok")
case true, false:
fmt.Println("ok")
case true || false:
fmt.Println("ok")
case true,
false:
fmt.Println("starting whitespace multiline case")
case true ||
false:
fmt.Println("starting whitespace multiline case")
case true,
false:
fmt.Println("ending whitespace multiline case")
case true,
false:
fmt.Println("last case should also fail")
}
}`),
expectedErrorStrings: []string{
"block should not end with a whitespace (or comment)",
"block should not start with a whitespace",
"block should not start with a whitespace",
"block should not end with a whitespace (or comment)",
},
},
}

for _, tc := range cases {
Expand Down

0 comments on commit de564df

Please sign in to comment.