Skip to content
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
8 changes: 8 additions & 0 deletions rule/unreachable-code.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func (*UnreachableCodeRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fail
failures = append(failures, failure)
}

testingFunctions := map[string]bool{
"Fatal": true,
"Fatalf": true,
"FailNow": true,
}
branchingFunctions := map[string]map[string]bool{
"os": {"Exit": true},
"log": {
Expand All @@ -26,6 +31,9 @@ func (*UnreachableCodeRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fail
"Panicf": true,
"Panicln": true,
},
"t": testingFunctions,
"b": testingFunctions,
"f": testingFunctions,
}

w := lintUnreachableCode{onFailure, branchingFunctions}
Expand Down
23 changes: 23 additions & 0 deletions testdata/unreachable-code.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"testing"
)

func foo() int {
Expand Down Expand Up @@ -35,3 +36,25 @@ func g() {

fmt.Println("Bye, playground")
}

func TestA(t *testing.T) {
tests := make([]int, 100)
for i := range tests {
println("i: ", i)
if i == 0 {
t.Fatal("i == 0") // MATCH /unreachable code after this statement/
println("unreachable")
continue
}
if i == 1 {
t.Fatalf("i:%d", i) // MATCH /unreachable code after this statement/
println("unreachable")
continue
}
if i == 2 {
t.FailNow() // MATCH /unreachable code after this statement/
println("unreachable")
continue
}
}
}