Radar · Go · Archive · Week 8 · Feb 17 – 23, 2025
Deprecate parser.ParseDir
Nice to knowtooling
- What changed
- The Go team marked
parser.ParseDiras deprecated. It will still exist and be usable, but it returnsast.Package, which is already deprecated. - Production impact
- The source does not say.
- Try it
- Run
go veton a project that usesparser.ParseDirto see the deprecation warning. - Source
- github.com/golang/go/issues/71122
Understand it, then run it
The parser.ParseDir function is a helper that walks a directory and turns every Go file it finds into an abstract syntax tree (AST). The Go team has marked this helper as *deprecated*. That means it still works, but the type it returns, ast.Package, is also deprecated. When you use parser.ParseDir in a new project, your IDE will warn you that the function is old and that you should look for a newer alternative.
The warning does not break your code; it just tells you that the library may remove the function in a future release. The change is part of the normal evolution of the standard library, where older APIs are phased out gradually.
If you are writing a small script or a learning example, you can keep using parser.ParseDir. Just be aware that in the future you might need to switch to a different approach, such as walking the directory yourself and calling parser.ParseFile on each file.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed