Skip to content

Commit f731efb

Browse files
committed
tools/syz-linter: suggest any instead of interface{}
Any is the preferred over interface{} now in Go.
1 parent 0f173f4 commit f731efb

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

tools/syz-linter/linter.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ func run(p *analysis.Pass) (any, error) {
7777
pass.checkIfStmt(n)
7878
case *ast.AssignStmt:
7979
pass.checkAssignStmt(n)
80+
case *ast.InterfaceType:
81+
pass.checkInterfaceType(n)
8082
}
8183
return true
8284
})
@@ -406,3 +408,9 @@ func (pass *Pass) checkAssignStmt(n *ast.AssignStmt) {
406408
}
407409
pass.report(n, "Don't duplicate loop variables. They are per-iter (not per-loop) since go122.")
408410
}
411+
412+
func (pass *Pass) checkInterfaceType(n *ast.InterfaceType) {
413+
if len(n.Methods.List) == 0 {
414+
pass.report(n, "Use any instead of interface{}")
415+
}
416+
}

tools/syz-linter/testdata/src/lintertest/lintertest.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,11 @@ func loopvar() {
144144
_, _ = i, v
145145
}
146146
}
147+
148+
func anyInterface() interface{} { // want "Use any instead of interface{}"
149+
var v interface{} // want "Use any instead of interface{}"
150+
func(interface{}) {} (v) // want "Use any instead of interface{}"
151+
var y any
152+
func(any) {} (y)
153+
return v
154+
}

0 commit comments

Comments
 (0)