Writing a Static Analyzer for Go Code
summary
Builds a static analyzer that finds missing closes, double closes and missing error handling by matching short variable declarations that yield an io.Closer and an error, walking the AST with the inspector and withStack, using types.Info to check interfaces, scanning subsequent statements for calls to Close and for an if that references the error, counting closes and reporting failures with pass.Reportf; packaged as a singlechecker CLI and successfully flags real violations in real packages.
AI-written summary · about
chapters (13)
- 0:00Introduction
- 8:23Writing a static analysis tool
- 13:55Run method
- 16:43Check for assignment statement
- 18:13Iterating over assignment statement
- 19:51Defining closer and error types
- 22:51Checking for close
- 24:46Improving close
- 25:16Handling defer
- 25:49Handling errors
- 27:16Close function
- 29:32Single checker
- 30:47Conclusion








