1
0
mirror of https://github.com/mgechev/revive.git synced 2025-10-30 23:37:49 +02:00

add testing.FailNow and related function to unreachable check (#711)

Signed-off-by: Abirdcfly <fp544037857@gmail.com>
This commit is contained in:
Abirdcfly
2022-07-21 06:41:31 +08:00
committed by GitHub
parent 20101b3a2d
commit fcc59adb72
2 changed files with 31 additions and 0 deletions

View File

@@ -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": {
@@ -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}

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"testing"
)
func foo() int {
@@ -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
}
}
}