Skip to content

Commit

Permalink
empty blocks may range over multiple lines, so it's not enough to jus…
Browse files Browse the repository at this point in the history
…t reduce by 1 line.

Now virtually collapsing empty labeled blocks will
* reveal diff in line numbers and lead to reasonBlockEndsWithWS
* allow empty labeled blocks at the end of another block (#92)
  • Loading branch information
Oppodelldog authored and bombsimon committed Oct 3, 2020
1 parent 560880c commit 52b83c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion wsl.go
Expand Up @@ -1141,7 +1141,7 @@ func (p *Processor) nodeEnd(node ast.Node) int {
var line = p.fileSet.Position(node.End()).Line

if isEmptyLabeledStmt(node) {
return line - 1
return p.fileSet.Position(node.Pos()).Line
}

return line
Expand Down
14 changes: 13 additions & 1 deletion wsl_test.go
Expand Up @@ -66,7 +66,7 @@ func TestGenericHandling(t *testing.T) {
}`),
},
{
description: "no false positives for empty labels",
description: "no false positives for empty labeled blocks",
code: []byte(`package main
func main() {
goto end;
Expand Down Expand Up @@ -208,6 +208,18 @@ func TestShouldRemoveEmptyLines(t *testing.T) {
}
}`),
},
{
description: "whitespaces parsed correctly in labeled blocks",
code: []byte(`package main
func main() {
goto end
end:
}`),
expectedErrorStrings: []string{
reasonBlockEndsWithWS,
},
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 52b83c4

Please sign in to comment.