Workiva / dart_codemod

A library that makes it easy to write and run automated code modifications on a codebase.
Other
61 stars 11 forks source link

Add way to run codemods non-interactively #51

Open evanweible-wf opened 3 years ago

evanweible-wf commented 3 years ago

At Workiva, we've used this library to build codemods that we run in large batches in order to update our whole package ecosystem at once. When we do this, we use a tool that runs the codemods across all applicable projects and opens pull requests with the resulting changes. All of this happens from our CI system, so we have no need for running the codemods interactively - we always pass the --yes-to-all flag in.

For this use case, it'd be nice to have an alternative to runInteractiveCodemod() like runCodemod() (and runCodemodSequence()) that would skip all the interactivity between the terminal user and the codemod.

There are a few benefits to this:

Note that since we already suggest a pattern of writing your own executable that calls runInteractiveCodemod(), this would allow codemod authors to support both interactive and non-interactive modes, probably behind a flag. For example, they could define a -i | --interactive flag that decides whether the codemod is run via runInteractiveCodemod() or via runCodemod(). And a --dry-run flag could be used similarly; when enabled, it would run via runCodemod(dryRun: true).

After typing that last paragraph, I'm realizing that if we were to implement this, it would probably also be nice to export a basic CodemodCommandRunner class that would handle the above interactive/non-interactive/dry-run logic for simple use cases.