← Workshop

project · March 2024

Understanding codemods

Sample scripts that explain how codemods rewrite JavaScript safely, using jscodeshift.

stack
JavaScript, jscodeshift

On the workbench

  • remove-commentsStrips every comment block from a file.
  • to-arrow-functionsRewrites function definitions as arrow functions.
  • to-es6-importsTurns require() calls into ES module imports.

Build log

  1. Mar 2024 Wrote the three transformers with jscodeshift, alongside a talk on why codemods matter.

What it taught me

  • A codemod edits the meaning of code (its syntax tree), not its text, which is why it can be trusted across a whole codebase.

Swipe, or tap the time before or after