From 52b83c436db9d3fc9ea98bdc52e9cacab8f8ac8b Mon Sep 17 00:00:00 2001 From: Oppodelldog Date: Sat, 3 Oct 2020 12:42:20 +0200 Subject: [PATCH] empty blocks may range over multiple lines, so it's not enough to just 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) --- wsl.go | 2 +- wsl_test.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/wsl.go b/wsl.go index d7b5cc8..9fa00a3 100644 --- a/wsl.go +++ b/wsl.go @@ -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 diff --git a/wsl_test.go b/wsl_test.go index c7098b6..ffd24cc 100644 --- a/wsl_test.go +++ b/wsl_test.go @@ -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; @@ -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 {