4 ms·
Codemod – A library to assist with large-scale codebase refactoring
- pspeter3 9y agoI think this was open sourced earlier but I just discovered it. As a personal anecdote, I've written many ad hoc code mods while working on Luna2 (Asana's next framework) and had no idea one of our founders wrote this. He apparently assumed IDEs would just handle this by now.
- nathancahill 9y agoFacebook also maintains a JS codemod tool that React uses: https://github.com/facebook/jscodeshift https://github.com/facebook/jscodeshift
- bm_i 9y agojscodeshift (recast) is one of my favourite tools
- Etheryte 9y agoThis is nice, but I don't see the upside over using the tools provided by the IDE or editor of your choice. Some of the additional flags are interesting, true, but I can't really say I've ever felt a need for something like it.
- mayank 9y agoIt's meant for large codebases that can't be loaded into an IDE all at once, or for cases where you need to modify other people's code and automatically send them individual pull requests for approval.
- allendoerfer 9y agoNice project, but a less powerful version of vim's :argdo.
- fphilipe 9y agoOr :cdo when using the quickfix window.
- jameslk 9y agoI'd also recommend checking out https://github.com/Yelp/undebt https://github.com/Yelp/undebt which is a bit more robust it seems in the search aspect, since it's grammar-based instead of regex-based.
- paulie_a 9y agoI have explored undebt and it has some very useful examples. But generally they seem to be low hanging fruit. I really would love to see more specific implementations and use cases
- craptocurrency 9y agowaste
- stringham 9y agoI find the idea of https://github.com/facebook/jscodeshift https://github.com/facebook/jscodeshift to be really useful. I've started writing small scripts using the TypeScript parser as a library to make meaningful improvements in our codebase. Since JavaScript is valid TypeScript syntax the scripts work on both. For example, I wrote a small script to change var to let or const when possible. It uses the AST to check scoping rules and to check if a variable is ever reassigned. Writing scripts like this is way more effective than doing it by hand.
- amenghra 9y agoThis code was open sourced in 2008, with a few improvements here and there until 2010. Codemod is great, but there are better tools out there (pfff by facebook, IntelliJ plugins, etc). It's too bad the readme doesn't do a great job explaining that.
- mygosh 9y agoOr just use a language that supports large scale refactoring, say Java, C#, perhaps even C++ if you are careful. I generally don't like dynamic languages for large projects exactly because of this. You can't safely and quickly do large scale refactorings, a point that will come back and haunt you sooner or later. No matter how good you are or how much care you take, the code will rot significantly more than in Java/C# because you just can't quickly refactor stuff across the entire codebase, so you won't.
- xaedes 9y agoI also like Clang Tools for C++ AST and programmatic refactoring. Much better than regex replace. What exactly is the benefit of Codemod? Too me it seems like a glorified regex replacer, nothing more. Suppose you have a function Foo::bar() and Bar::bar(). You decide to replace Bar::bar() by Bar::foo(). Good look with doing that via regex. Foo::bar() calls will most likely be affected as well. Matching directly on the AST solves this problem by explicitely matching all Bar::bar() calls. What I really want: a language agnostic abstract syntax tree parser, matcher and transformer. AST matchers and Clang refactoring tools: http://eli.thegreenplace.net/2014/07/29/ast-matchers-and-clang-refactoring-tools http://eli.thegreenplace.net/2014/07/29/ast-matchers-and-cla... Refactoring C++ with Clang with cool examples: https://www.youtube.com/watch?v=yuIOGfcOH0k https://www.youtube.com/watch?v=yuIOGfcOH0k Clang rename refactoring tool: https://clang.llvm.org/extra/clang-rename.html https://clang.llvm.org/extra/clang-rename.html