aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2025-12-19 12:42:34 +0100
committerAleksandr Nogikh <nogikh@google.com>2025-12-22 02:13:00 +0000
commit49b0fb03849fcfed4c30395cb7da84491de40a58 (patch)
tree534db4d3b497249a8938cc1092b9a4f587d8d3da /tools
parenta83befa0d111a0ba6fac52d763e93c76a2ef94d4 (diff)
tools/syz-linter: suggest any instead of interface{}
Any is the preferred over interface{} now in Go.
Diffstat (limited to 'tools')
-rw-r--r--tools/syz-linter/linter.go8
-rw-r--r--tools/syz-linter/testdata/src/lintertest/lintertest.go8
2 files changed, 16 insertions, 0 deletions
diff --git a/tools/syz-linter/linter.go b/tools/syz-linter/linter.go
index 5b3d2210d..97e8f2963 100644
--- a/tools/syz-linter/linter.go
+++ b/tools/syz-linter/linter.go
@@ -77,6 +77,8 @@ func run(p *analysis.Pass) (any, error) {
pass.checkIfStmt(n)
case *ast.AssignStmt:
pass.checkAssignStmt(n)
+ case *ast.InterfaceType:
+ pass.checkInterfaceType(n)
}
return true
})
@@ -406,3 +408,9 @@ func (pass *Pass) checkAssignStmt(n *ast.AssignStmt) {
}
pass.report(n, "Don't duplicate loop variables. They are per-iter (not per-loop) since go122.")
}
+
+func (pass *Pass) checkInterfaceType(n *ast.InterfaceType) {
+ if len(n.Methods.List) == 0 {
+ pass.report(n, "Use any instead of interface{}")
+ }
+}
diff --git a/tools/syz-linter/testdata/src/lintertest/lintertest.go b/tools/syz-linter/testdata/src/lintertest/lintertest.go
index 4a3a48656..60b59c0ae 100644
--- a/tools/syz-linter/testdata/src/lintertest/lintertest.go
+++ b/tools/syz-linter/testdata/src/lintertest/lintertest.go
@@ -144,3 +144,11 @@ func loopvar() {
_, _ = i, v
}
}
+
+func anyInterface() interface{} { // want "Use any instead of interface{}"
+ var v interface{} // want "Use any instead of interface{}"
+ func(interface{}) {} (v) // want "Use any instead of interface{}"
+ var y any
+ func(any) {} (y)
+ return v
+}