Writing codemods with jscodeshfit
Published onThere are times in your project when you need to update a lot of code in a similar way. For example, you updated a library that has a breaking change, so you want to update your code to use the new API. Let’s also say that the required changes are very simple and don’t require any thought, but not simple enough for a regex. Making these changes manually in large codebases is not only tedious, but sometimes even not worth it, so what can we do?
Regular expressions are limited because they don’t understand syntax, but codemods do because they use abstract syntax trees (ASTs). In the following talk I give an introduction to writing codemods with Facebook’s tool jscodeshift: