How to build ast tree also for dependencies


I’m building sort of linter for my go lang project and would like to find all the types implementing Close() method (so later on i can check either it is called). Project is module based.
I managed to do this for the code i own using token.NewFileSet, parser.ParseDir and ast.Walk.
The problem i have is how to parse also all the dependencies in order to scan types declarations there.

Would appreciate any help.

I recommend this package: packages package - - Go Packages

It lets you specify NeedImports in the Config.LoadMode so you can then load those packages (and keep going, recursively, if you want).

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.