Skip to content

Commit

Permalink
The end pos of an empty label always falls to the next line so wsl ra…
Browse files Browse the repository at this point in the history
…ises a warning where it's not necessary.

This compensates the line number for empty labels and avoids the false positive
  • Loading branch information
Oppodelldog authored and bombsimon committed Oct 3, 2020
1 parent b5de1fb commit 560880c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
19 changes: 18 additions & 1 deletion wsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,24 @@ func (p *Processor) nodeStart(node ast.Node) int {
}

func (p *Processor) nodeEnd(node ast.Node) int {
return p.fileSet.Position(node.End()).Line
var line = p.fileSet.Position(node.End()).Line

if isEmptyLabeledStmt(node) {
return line - 1
}

return line
}

func isEmptyLabeledStmt(node ast.Node) bool {
v, ok := node.(*ast.LabeledStmt)
if !ok {
return false
}

_, empty := v.Stmt.(*ast.EmptyStmt)

return empty
}

// Add an error for the file and line number for the current token.Pos with the
Expand Down
8 changes: 8 additions & 0 deletions wsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ func TestGenericHandling(t *testing.T) {
s := func() error { return nil }
}`),
},
{
description: "no false positives for empty labels",
code: []byte(`package main
func main() {
goto end;
end:
}`),
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 560880c

Please sign in to comment.