| name | refactor |
| description | Code refactoring with AI assistance. Use for modernizing code, converting JavaScript to TypeScript, class to hooks conversions, and systematic renaming. |
Refactoring Assistant
Systematic code refactoring with AI guidance.
Prerequisites
pip install google-generativeai
export GEMINI_API_KEY=your_api_key
npm install -g jscodeshift
npm install -g typescript
Refactoring Operations
JavaScript to TypeScript
mv file.js file.ts
CODE=$(cat file.ts)
gemini -m pro -o text -e "" "Convert this JavaScript to TypeScript with proper types:
$CODE
Requirements:
- Add explicit types for function parameters and returns
- Create interfaces for object shapes
- Use strict TypeScript (no any unless necessary)
- Preserve functionality exactly"
Class to React Hooks
CODE=$(cat ClassComponent.tsx)
gemini -m pro -o text -e "" "Convert this React class component to functional component with hooks:
$CODE
Requirements:
- Convert state to useState
- Convert lifecycle methods to useEffect
- Convert class methods to functions
- Preserve all functionality
- Use proper TypeScript types"
Modernize Code
CODE=$(cat legacy.ts)
gemini -m pro -o text -e