4 ms·
Navigate ASTs with x-path-like queries
- anitil 4y agoThis is great! I think I've seen a similar thing used for picking up issues like deprecated usages and things like that. I've found myself manually writing code for finding things in python's AST but a tool like this would be much more succinct Edit: the author's website is a delight - http://engelschall.com/ http://engelschall.com/
- dimator 4y agofor work, i wrote a tool that takes an astroid AST tree and translates it into XML (in memory), which are very close in spirit since they're both tree-like structures. this lets one write linter tools using familiar XPath queries and assert on the results. it's good for some kinds of pattern/anti-pattern enforcement. https://pylint.pycqa.org/projects/astroid/en/latest/index.html https://pylint.pycqa.org/projects/astroid/en/latest/index.ht...
- anitil 4y agoThat's a clever way of leveraging existing tooling! I hadn't heard of astroid before, I've always used the built in ast module
- bdg 4y agoJust curious, what do you use the resultant XML for? Analysis? Rewriting code?
- dimator 4y agono rewrites (the AST->XML bridging is one way), we use it for checking for forbidden patterns that we don't want developers using.
- bdg 4y ago>I've found myself manually writing code for finding things in python's AST but a tool like this would be much more succinct Wow, I also am writing a tool for finding things in the Python AST: https://github.com/Incognito/python-architecture-linter https://github.com/Incognito/python-architecture-linter It does other things too, but one of the key features is reading the AST. It's a bit of a prototype but if you want to jam together on a project I'd be open to it.
- anitil 4y agoYour tool is _much_ more powerful than what I've been doing. I've been looking at things like 'what proportion of functions have docstrings, and what format are they in?' or 'how much of our codebase is using typing?' Yours is much more ambitious, if I understand it correctly?
- mdaniel 4y ago... "for JavaScript" would have helped I hope in addition to the cute operators they also support actual XPath, since it'd be less reinventing the wheel for those who already know XPath Also, prior art for static analysis using XPath: https://pmd.github.io/pmd-6.47.0/ https://pmd.github.io/pmd-6.47.0/