refactoring

Guide linter-driven refactoring of React/TypeScript code to reduce complexity.

4|1|Updated Oct 13, 2025
One-click install
npx skills add https://github.com/buzzdan/ai-coding-rules --skill refactoring-buzzdan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactoring
Source: https://github.com/buzzdan/ai-coding-rules/tree/main/ts-react-linter-driven-development/skills/refactoring
Command: npx skills add https://github.com/buzzdan/ai-coding-rules --skill refactoring-buzzdan

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Linter-driven refactoring patterns to reduce complexity and improve code quality in React/TypeScript. Use when ESLint or SonarJS reports high cognitive, cyclomatic, or expression complexity, or when UI code is hard to read and maintain. Applies component extraction, hook extraction, and simplification patterns to structure code into clear abstractions.

Core Features & Use Cases

  • Extract Custom Hook: move business logic out of components for reuse and easier testing.
  • Extract Component: break large components into focused, reusable parts.
  • Early Returns / Guard Clauses: reduce nesting and improve readability.
  • Extract Helper Functions: isolate complex logic behind descriptive names.
  • Form Validation Patterns (Zod): move validation out of UI components for consistency.
  • Storifying: structure code into consistent abstraction layers (component, hook, service).

Quick Start

Refactor a complex React component by extracting a custom hook, splitting UI into focused components, and adding Zod validation.

Frequently Asked Questions about refactoring

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce high cognitive and cyclomatic complexity in React TypeScript components?

Reduce cognitive and cyclomatic complexity in React TypeScript by applying linter-driven refactoring patterns like Extract Custom Hook, Extract Component, and Early Returns to structure code into clear, testable abstractions.

What is the best way to refactor a large React component for readability?

The best way to refactor a large React component is to break it into focused parts using Extract Component, move business logic with Extract Custom Hook, and apply Zod-based validation to separate concerns and improve readability.

How do I move form validation logic out of my React UI components?

Move form validation logic out of React UI components by applying Zod-based validation patterns, isolating complex logic behind descriptive helper functions, and structuring code into consistent component, hook, and service layers.

When should I use early returns and guard clauses in React TypeScript?

Use early returns and guard clauses in React TypeScript when ESLint or SonarJS reports high expression complexity, or when deep nesting makes UI code hard to read, to flatten structure and improve readability.

Does linter-driven refactoring work with existing SonarJS complexity rules?

Yes, linter-driven refactoring works with existing SonarJS complexity rules by directly targeting reported high cognitive, cyclomatic, and expression complexity through incremental component extraction and hook extraction patterns.

What are the limitations of extracting custom hooks for React refactoring?

Extracting custom hooks for React refactoring is limited by the need for safe, incremental application; it primarily targets UI and form logic, so complex backend logic may require alternative helper function extraction patterns.