3 ms·
This sort of heuristic bugs me too. We should be able to write language server-adjacent tools which could do this sort of thing as easily as grep. You could do
by l0b0 3y ago
This sort of heuristic bugs me too. We should be able to write language server-adjacent tools which could do this sort of thing as easily as grep. You could do a lot of useful stuff with that, for example to implement custom linting rules:
- Count non-comment tokens within each scope, to look for complex scopes: `foo --tokens --exclude-comments --group-by=scope`
- Count expressions (as opposed to just SLOC) per function: `foo --expressions --group-by=function` piped to `uniq`
- Get the functions and their argument count: `foo --arguments --count --group-by=function`
- Find very short or long names: `foo --names --sort-by=length` piped to `head`/`tail`
- skydhash 3y agoMost languages are open source, it should not be difficult to extract their parser and do this stuff. As far as I know, only Babel ( JavaScript ) and Java have a plugin ecosystem, but only related to compiling.
- deleted 3y ago[deleted]
- eesmith 3y agoWhile I have not tried them out, I know there are tools along these lines. See Tree-sitter at https://tree-sitter.github.io/tree-sitter/ https://tree-sitter.github.io/tree-sitter/ , and as an example project which uses it to parse different languages in a line-oriented manipulable way, see https://pypi.org/project/code-ast/ https://pypi.org/project/code-ast/ . At the very least, the hard part - parsing the different languages - is done.