Skip to content

signed/codemods

Repository files navigation

codemods - what is it about

A small collection of AST transformations to refactor typescript code. All transformations are driven by individual needs and are by no means a fully working and supported migration tool. There is no plan to provide a command line runner or to publish the transformers as npm package. To use it checkout the code, run it and make adjustments as you need them. If they are useful too other, open a PR.

Replace default exports with named exports

This blog post gives a bunch of drawbacks when using default exports. Replacing default exports is a two-step process:

  1. Replace the default export in the declaring module with a named export
  2. Update all depending on modules that do a default export to use the new named export

Opportunities

  • support for .tsx files

Remove copyright headers

To me copyright headers at the top of a file are noise and distraction. If you are allowed to remove them, this should help.

Opportunities

  • Implement it

Identify unused modules and unused exports

Opportunities

  • Implement it

tools available for the task

Examples on how to use jscodeshift

Replace default imports / exports with named imports / exports

  • only replace default imports if the source is in the project

notes

To get a typescript AST like you get with jscodeshift

  1. change from acorn to @babel/parser
  2. click ⚙️ to open the @babel/parser settings
  3. uncheck flow
  4. check typescript

scope

Questions

remove console.log calls

Other jscodeshift codemods on the web

Other tools to write and run codemodes

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published