1
0
mirror of https://github.com/mgechev/revive.git synced 2024-12-12 10:44:59 +02:00
revive/testdata/unnecessary_stmt.go
2024-11-11 19:31:18 +01:00

50 lines
890 B
Go

package fixtures
func foo(a, b, c, d int) {
switch n := node.(type) { // MATCH /switch with only one case can be replaced by an if-then/
case *ast.SwitchStmt:
caseSelector := func(n ast.Node) bool {
_, ok := n.(*ast.CaseClause)
return ok
}
cases := pick(n.Body, caseSelector, nil)
if len(cases) == 1 {
cs, ok := cases[0].(*ast.CaseClause)
if ok && len(cs.List) == 1 {
w.onFailure(lint.Failure{
Confidence: 1,
Node: n,
Category: "style",
Failure: "switch can be replaced by an if-then",
})
}
}
}
}
func bar() {
a := 1
switch a {
case 1, 2:
a++
}
loop:
for {
switch a {
case 1:
a++
println("one")
break // MATCH /omit unnecessary break at the end of case clause/
case 2:
println("two")
break loop
default:
println("default")
}
}
return // MATCH /omit unnecessary return statement/
}