Assess, plan, evolve.
Reusable compiler-aware skills that help coding agents understand, plan, and safely evolve your codebase.
9 packages
This codemod improves error handling in SvelteKit by updating the way errors are returned in the load function. In SvelteKit 1, errors were handled inconsistently, often missing the status property or failing to trigger the handleError hook. SvelteKit 2 standardizes error handling by automatically including the status and message properties in error responses. ### Change Summary In SvelteKit 1, errors were returned with just the error property. In SvelteKit 2, errors are now returned with both error and status properties, ensuring consistent error handling and making it easier to manage different HTTP statuses. This codemod ensures that all errors returned from the load function are compatible with SvelteKit 2’s enhanced error handling. ### Example ### Before ```ts // Before (SvelteKit 1) import { error } from '@sveltejs/kit'; export async function load({ params }) { try { const data = await fetchData(params.id); if (!data) { throw error(404, 'Data not found'); } return { props: { data } }; } catch (err) { // Errors might not always trigger handleError if (err.status === 404) { console.error("Page not found", err); } return { props: { error: err.message } }; } } ``` ### After ```ts // After (SvelteKit 2) import { error } from '@sveltejs/kit'; export async function load({ params }) { try { const data = await fetchData(params.id); if (!data) { throw error(404, 'Data not found'); } return { props: { data } }; } catch (err) { // With the improved error handling in SvelteKit 2, errors are now consistent // and trigger the handleError hook with status and message. return { props: { error: err.message, status: err.status || 500 } }; } } ```
- sveltekit
- typescript
- +6
This codemod automates the update of your `onChange` event handler function to support the new `Descendant[]` type and selection handling introduced in version 0.104. **Before (v0.88):** ```typescript const onChange = value => { setValue(value); }; ``` **After (v0.104)** ```typescript const onChange = (newValue: Descendant[]) => { setValue(newValue); // Additional state management if needed const selection = editor.selection; if (selection) { // Handle selection changes } }; ```
- typescript
This codemod shows how to migrate cursor and ```selection``` handling from Slate v0.88 to v0.104, including the Preventing runtime errors from null selections. ## Code Changes ### Version 0.88 ```typescript const selection = editor.selection; const start = Range.start(selection); ``` ### Version 0.104 ```typescript const selection = editor.selection as Range | null; if (selection) { const start = Range.start(selection); // Selection is now safely typed and null-checked } ``` ## Key Changes - Added explicit type casting to `Range | null` - Implemented null safety check using conditional block - Ensures selection exists before accessing its properties ## Migration Benefits - Prevents runtime errors from null selections - Provides better TypeScript type safety - Follows current best practices for Slate selection handling
- slate
- javascript
# es-errors Codemod ## Introduction This codemod replaces the use of the `es-errors` module and its specific error constructors with built-in JavaScript error types. This change reduces unnecessary dependencies and leads to a more lightweight codebase while ensuring that error handling remains efficient and standard. ### Before ```javascript import { Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError } from 'es-errors'; const evalError = new EvalError('This is an evaluation error'); const rangeError = new RangeError('This is a range error'); ``` ### After ```javascript const evalError = new EvalError('This is an evaluation error'); const rangeError = new RangeError('This is a range error'); ```
- e18e
- module-replacement
# 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 import { error } from '@sveltejs/kit'; throw error(500, 'Internal Server Error'); import { redirect } from '@sveltejs/kit'; throw redirect(301, '/new-location'); import { redirect } from '@sveltejs/kit'; // Redirect if the user is not authenticated if (!user.isAuthenticated) { throw redirect(303, '/login'); } ``` ### After ```typescript import { error } from '@sveltejs/kit'; error(500, 'Internal Server Error'); import { redirect } from '@sveltejs/kit'; redirect(301, '/new-location'); import { redirect } from '@sveltejs/kit'; // Redirect if the user is not authenticated if (!user.isAuthenticated) { redirect(303, '/login'); } ``` ## License MIT License ```
- sveltekit
- typescript
- +6
This codemod assists in removing the use of Fibers from your Meteor codebase, refactoring your code to utilize the modern `async/await` pattern introduced in Meteor v3. You can find the implementation of this codemod in the Studio [here](https://go.codemod.com/7zbBQE4) ## Fibers Removal With the release of Meteor v3, Fibers are no longer necessary. The `async/await` syntax provides a cleaner and more modern approach to handling asynchronous operations in your code. This codemod will automatically refactor your code to replace Fibers with `async/await`. ## Example Transformation ### `Future` to `Promise` with `async/await` **Before:** ```ts const Future = Npm.require("fibers/future"); function someFunction() { const future = new Future(); someAsyncFunction((error, result) => { if (error) { future.throw(error); } else { future.return(result); } }); return future.wait(); } ``` **After:** ```ts async function someFunction() { return new Promise((resolve, reject) => { someAsyncFunction((error, result) => { if (error) { reject(error); } else { resolve(result); } }); }); } ```
- meteor
- v3
- +1
This codemod updates synchronous MongoDB operations in a Meteor project to use their asynchronous counterparts, making the code compatible with modern JavaScript best practices (using `async/await`). It transforms methods such as `find`, `findOne`, `insert`, `update`, `remove`, and `upsert` to their asynchronous equivalents by appending `Async` to method names and introducing `await`. ### Example This codemod converts synchronous MongoDB queries and updates into asynchronous methods for better code readability, performance, and error handling. ### Before ```ts const docs = MyCollection.find({ _id: "123" }).fetch(); const doc = MyCollection.findOne({ _id: "123" }); ``` ### After ```ts const docs = await MyCollection.find({ _id: "123" }).fetchAsync(); const doc = await MyCollection.findOneAsync({ _id: "123" }); ``` ### Transformations This codemod handles various MongoDB operations and converts them into asynchronous functions. #### Example 1: Fetching documents **Before:** ```ts const docs = MyCollection.find({ _id: "123" }).fetch(); ``` **After:** ```ts const docs = await MyCollection.find({ _id: "123" }).fetchAsync(); ``` #### Example 2: Fetching a single document **Before:** ```ts const doc = MyCollection.findOne({ _id: "123" }); ``` **After:** ```ts const doc = await MyCollection.findOneAsync({ _id: "123" }); ``` #### Example 3: Updating documents **Before:** ```ts MyCollection.update({ _id: "123" }, { $set: { name: "John" } }); const updatedDocument = MyCollection.findOne({ _id: "123" }); ``` **After:** ```ts await MyCollection.updateAsync({ _id: "123" }, { $set: { name: "John" } }); const updatedDocument = await MyCollection.findOneAsync({ _id: "123" }); ``` #### Example 4: Inserting, updating, removing, and upserting documents **Before:** ```ts MyCollection.insert({ name: "Jane", age: 30 }); MyCollection.update({ _id: "123" }, { $set: { name: "John" } }); MyCollection.remove({ _id: "123" }); MyCollection.upsert({ _id: "123" }, { $set: { name: "John" } }); ``` **After:** ```ts await MyCollection.insertAsync({ name: "Jane", age: 30 }); await MyCollection.updateAsync({ _id: "123" }, { $set: { name: "John" } }); await MyCollection.removeAsync({ _id: "123" }); await MyCollection.upsertAsync({ _id: "123" }, { $set: { name: "John" } }); ``` --- This codemod simplifies migration from synchronous MongoDB methods to their asynchronous versions, improving performance and allowing better control over the code execution flow.
- meteor
- v3
This codemods designed to facilitate the migration of your project from React Router to version 7. Each codemod targets specific changes and improvements introduced in React Router v7, ensuring a smoother transition. ## Included Codemods The following codemods are included in this recipe: 1. **[`react-router/7/relative-links`](https://codemod.com/registry/react-router-7-relative-links)** Updates relative link paths to comply with v7 standards. 2. **[`react-router/7/add_v7_relativeSplatPath_Flag`](https://codemod.com/registry/react-router-7-add_v7_relativeSplatPath_Flag)** Adds the `relativeSplatPath` flag to routes to support relative splat behavior. 3. **[`react-router/7/errorfirst-mutation-reorder`](https://codemod.com/registry/react-router-7-errorfirst-mutation-reorder)** Reorders error-first mutation signatures for compatibility with v7. 4. **[`react-router/7/form-methods-post-get-to-uppercase`](https://codemod.com/registry/react-router-7-form-methods-post-get-to-uppercase)** Converts form method strings (`post`, `get`) to uppercase as required by v7. 5. **[`react-router/7/route-wildcard-to-nested`](https://codemod.com/registry/react-router-7-route-wildcard-to-nested)** Transforms route wildcards into nested routes for improved routing management. 6. **[`react-router/7/add_v7_startTransition_Flag`](https://codemod.com/registry/react-router-7-add-v7-startTransition-flag)** Introduces the `startTransition` flag to enhance transitions in routing. 7. **[`react-router/7/add_v7_fetcherPersist_Flag`](https://codemod.com/registry/react-router-7-add_v7_fetcherPersist_Flag)** Adds the `fetcherPersist` flag to improve data fetching mechanisms. 8. **[`react-router/7/add_v7_normalizeFormMethod`](https://codemod.com/registry/react-router-7-add_v7_normalizeFormMethod)** Normalizes form methods to align with v7 conventions. 9. **[`react-router/7/add_v7_partialHydration_Flag`](https://codemod.com/registry/react-router-7-add_v7_partialHydration_Flag)** Integrates the `partialHydration` flag to support enhanced hydration strategies. 10. **[`react-router/7/add_v7_skipActionStatusRevalidation_Flag`](https://codemod.com/registry/react-router-7-add_v7_skipActionStatusRevalidation_Flag)** Adds the `skipActionStatusRevalidation` flag for improved action handling. ---
- react-router
- migration
- +1
This codemod is designed to help you migrate your existing codebase from using the native `fetch` API to the more concise and convenient `ky` HTTP client library. By running this codemod, you can automatically update your code to leverage `ky`'s features, such as simpler syntax for common use cases like JSON requests and responses. ## Detailed Description The codemod performs the following transformations: - Replaces `fetch` calls with `ky` methods (`ky.get`, `ky.post`, `ky.put`, `ky.delete`). - Simplifies request setup by using `ky`'s built-in methods for JSON handling (`.json()`). - Removes manual error checking (`!resp.ok`), as `ky` automatically throws errors for non-2xx responses. - Streamlines the code by reducing boilerplate and improving readability. ## Example ### Before ```ts export async function getTodos() { const resp = await fetch(`/todos`); if (!resp.ok) throw resp; return resp.json(); } export async function addTodo(todo) { const resp = await fetch(`/todo`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ todo }), }); if (!resp.ok) throw resp; return resp.json(); } export async function updateTodo(todo) { const resp = await fetch(`/todo/${todo.id}`, { method: 'PUT', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ todo }), }); if (!resp.ok) throw resp; } export async function deleteTodo(todoId) { const resp = await fetch(`/todo/${todoId}`, { method: 'DELETE', }); if (!resp.ok) throw resp; } ``` ### After ```ts import ky from 'ky'; export async function getTodos() { const resp = await ky.get(`/todos`); return resp.json(); } export async function addTodo(todo) { const resp = await ky.post(`/todo`, { json: { todo }, }); return resp.json(); } export async function updateTodo(todo) { const resp = await ky.put(`/todo/${todo.id}`, { json: { todo }, }); } export async function deleteTodo(todoId) { const resp = await ky.delete(`/todo/${todoId}`); } ``` This codemod streamlines your existing fetch functions by converting them to use `ky`, eliminating unnecessary code, and making your HTTP requests more readable and maintainable.
- fetch-to-ky
Build your own codemod!
Describe the migration you need and Codemod Agent will create a codemod for you.
Ready to evolve your codebase?
Build tailored, compiler-aware skills to assess, plan, and automate complex codebase changes.