P

replace-throw-with-error-call

How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

Replace Throw Statements with Direct Function Calls

This codemod simplifies error handling and redirects in your TypeScript project by replacing throw error() and throw redirect() statements with direct calls to error() and redirect(). This change aligns with modern practices and results in cleaner, more readable code.

Transformations

This codemod performs the following transformations:

  • Error Handling: Transforms throw error(status, message) into error(status, message).
  • Redirects: Transforms throw redirect(status, url) into redirect(status, url).

Usage

To apply this codemod, run the workflow script on your TypeScript files. Ensure you have the necessary dependencies installed and your project is configured to use this codemod.

Example

Before

typescript

After

typescript

License

MIT License

Ready to contribute?

Build your own codemod and share it with the community.