I love this idea for improving the AST node matching capabilities of golang, and I'd like to contribute. The go/ast package is bare bones with only slight improvements in go/astutil. This is really a shame, since golang is so often used with build tools and has utilities like go generate for build tooling.
This repo contains powerful node matching capabilities like what's possible in popular parsers (ESLint, Babel). Unfortunately it's not very discoverable - see this post from the SeatGeek software dev blog lamenting the lack of a Golang AST node matcher - or well-documented, so I'd like to help out on both those fronts if I can. To that end, my ideas are:
- start by updating the README to offer an overview of the capabilities of
goastch and sort the APIs into these capabilities.
- continue by adding common recipes to the README
- structural matching, ex: the
if err != nil matcher in the blog post above
- logical matching, ex:
Any('if err != nil', 'if nil != err') for files not suppressing errors, else no match
- traversal matching, ex: a
go func() {}() literal contains a reference to a loop variable in its closure (this is being fixed in Go 1.22, may need to think of a better example)
- goal is to use every user-facing function in 1 or more recipes to provide functional documentation of the APIs
- since the most common uses of an AST are linting/fixing and codemods, write a thin wrapper for interfacing with
go/analysis or provide an example of how to do so
I also have ideas for features and extending functionality, but I'd love to see this project gain wider visibility. This seems like the lowest-hanging fruit to improve usability & visibility. Please let me know if you're interested and how I can help if so.
I love this idea for improving the AST node matching capabilities of golang, and I'd like to contribute. The go/ast package is bare bones with only slight improvements in go/astutil. This is really a shame, since golang is so often used with build tools and has utilities like
go generatefor build tooling.This repo contains powerful node matching capabilities like what's possible in popular parsers (ESLint, Babel). Unfortunately it's not very discoverable - see this post from the SeatGeek software dev blog lamenting the lack of a Golang AST node matcher - or well-documented, so I'd like to help out on both those fronts if I can. To that end, my ideas are:
goastchand sort the APIs into these capabilities.if err != nilmatcher in the blog post aboveAny('if err != nil', 'if nil != err')for files not suppressing errors, else no matchgo func() {}()literal contains a reference to a loop variable in its closure (this is being fixed in Go 1.22, may need to think of a better example)go/analysisor provide an example of how to do soI also have ideas for features and extending functionality, but I'd love to see this project gain wider visibility. This seems like the lowest-hanging fruit to improve usability & visibility. Please let me know if you're interested and how I can help if so.