1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-28 08:49:11 +02:00
revive/testdata/function_length2.go
2024-11-11 19:31:18 +01:00

105 lines
1.9 KiB
Go

package fixtures
import (
"fmt"
ast "go/ast"
"go/token"
)
func funLengthA() (a int) {
println()
println()
println()
println()
println()
}
func funLengthB(file *ast.File, fset *token.FileSet, lineLimit, stmtLimit int) []Message { // MATCH /maximum number of lines per function exceeded; max 5 but got 23/
if true {
a = b
if false {
c = d
for _, f := range list {
_, ok := f.(int64)
if !ok {
continue
}
}
switch a {
case 1:
println()
case 2:
println()
println()
default:
println()
}
}
}
return
}
func funLengthC(b []ast.Stmt) int { // MATCH /maximum number of lines per function exceeded; max 5 but got 23/
count := 0
for _, s := range b {
switch stmt := s.(type) {
case *ast.BlockStmt:
count += w.countStmts(stmt.List)
case *ast.ForStmt, *ast.RangeStmt, *ast.IfStmt,
*ast.SwitchStmt, *ast.TypeSwitchStmt, *ast.SelectStmt:
count += 1 + w.countBodyListStmts(stmt)
case *ast.CaseClause:
count += w.countStmts(stmt.Body)
case *ast.AssignStmt:
count += 1 + w.countFuncLitStmts(stmt.Rhs[0])
case *ast.GoStmt:
count += 1 + w.countFuncLitStmts(stmt.Call.Fun)
case *ast.DeferStmt:
count += 1 + w.countFuncLitStmts(stmt.Call.Fun)
default:
fmt.Printf("%T %v\n", stmt, stmt)
count++
}
}
return count
}
func funLengthD(b []ast.Stmt) int {
defer func() { println() }()
}
func funLengthE(b []ast.Stmt) int { // MATCH /maximum number of lines per function exceeded; max 5 but got 7/
defer func() {
if true {
println()
} else {
print()
}
}()
}
func funLengthF(b []ast.Stmt) int {
if true {
println()
} else {
print()
}
}
func funLengthG(b []ast.Stmt) int { // MATCH /maximum number of lines per function exceeded; max 5 but got 7/
go func() {
if true {
println()
} else {
}
}()
}
func funLengthH(b []ast.Stmt) int {
go func() {}()
println()
}