4 ms·
I'm honestly surprised we haven't seen complete democratization of linting/grepping/refactoring tools. Imagine being able to script a one-off refactor you want
by brundolf 6y ago
I'm honestly surprised we haven't seen complete democratization of linting/grepping/refactoring tools. Imagine being able to script a one-off refactor you want to make that's too project-specific to be included in the IDE itself.
Writing the parser is nontrivial, but once you have it it should be straightforward to expose a programmatic API for doing this stuff instead of trying to hardcode every useful linter rule into a single program.
- vbsteven 6y agoYou can do this with Rust using a combination of rustc, syn and a build.rs file. Then you can execute more Rust code on the parsed AST. In the JVM world annotation processors or compiler plugins can have access to the AST during compilation. Both in Kotlin and Java.
- lamontcg 6y agoWe do this with rubocop and its ability to parse the ruby AST. The API to actually write rules in rubocop is not particularly the best, but it has been highly successful in codebase and domain-specific ruby linting and autofixing.
- cjohansson 6y agoWriting a parser for one specific version of a language is one thing (nontrivial), but writing a parser than parsed most versions of most programming languages and keeping it up-to-date is a enormous undertaking and cannot be done by one person
- karlding 6y agoFor C/C++ code, you can already do refactoring using clang-tidy scripts [0], or even can write custom linters using libtooling [1] and leverage the AST Matchers [2] which work at the AST level. All that's needed is a compile_commands.json file which can be easily generated via most build systems, or you can use Bear [3]/some other tool (or write a script that logs all syscalls and generate it yourself). [0] https://releases.llvm.org/12.0.0/tools/clang/tools/extra/docs/clang-tidy/index.html https://releases.llvm.org/12.0.0/tools/clang/tools/extra/doc... [1] https://releases.llvm.org/12.0.0/tools/clang/docs/LibTooling.html https://releases.llvm.org/12.0.0/tools/clang/docs/LibTooling... [2] https://releases.llvm.org/12.0.0/tools/clang/docs/LibASTMatchers.html https://releases.llvm.org/12.0.0/tools/clang/docs/LibASTMatc... [3] https://github.com/rizsotto/Bear https://github.com/rizsotto/Bear
- elanning 6y agoI wrote a small VS code extension and pre-commit hook that might meet 80% of your needs: https://github.com/elanning/checkr https://github.com/elanning/checkr It is just simple regex at this time, but hopefully I can add something like CCGrep syntax in the future: https://github.com/yuy-m/CCGrep https://github.com/yuy-m/CCGrep