From shinpr-claude-code-workflows
Enforces React/TypeScript frontend rules for type safety with type guards and modern features, component design, state management, error handling, and refactoring. Use when implementing React components or frontend features.
npx claudepluginhub joshuarweaver/cascade-code-general-misc-1 --plugin shinpr-claude-code-workflowsThis skill uses the workspace's default tool permissions.
- **Aggressive Refactoring** - Prevent technical debt and maintain health
Creates isolated Git worktrees for feature branches with prioritized directory selection, gitignore safety checks, auto project setup for Node/Python/Rust/Go, and baseline verification.
Executes implementation plans in current session by dispatching fresh subagents per independent task, with two-stage reviews: spec compliance then code quality.
Dispatches parallel agents to independently tackle 2+ tasks like separate test failures or subsystems without shared state or dependencies.
Absolute Rule: Replace every any with unknown, generics, or union types. any disables type checking and causes runtime errors.
any Type Alternatives (Priority Order)
Type Guard Implementation Pattern
function isUser(value: unknown): value is User {
return typeof value === 'object' && value !== null && 'id' in value && 'name' in value
}
Modern Type Features
const config = { apiUrl: '/api' } satisfies Config - Preserves inferenceconst ROUTES = { HOME: '/' } as const satisfies Routes - Immutable and type-safetype UserId = string & { __brand: 'UserId' } - Distinguish meaningtype EventName = \on${Capitalize}`` - Express string patterns with typesType Safety in Frontend Implementation
unknown, validate with type guardsunknown, validateunknown, validateType Safety in Data Flow
unknown) → Type Guard → State (Type Guaranteed)Type Complexity Management
Component Design Criteria
State Management Patterns
useState for component-specific stateData Flow Principles
// Immutable state update — always create new arrays/objects
setUsers(prev => [...prev, newUser])
Function Design
function createUser({ name, email, role }: CreateUserParams) {}
Props Design (Props-driven Approach)
Environment Variables
process.env does not work in browsers// Use import.meta.env (not process.env — unavailable in browser bundles)
const config = {
apiUrl: import.meta.env.API_URL || 'http://localhost:3000',
appName: import.meta.env.APP_NAME || 'My App'
}
Security (Client-side Constraints)
.env files via .gitignore// Backend manages secrets, frontend accesses via proxy
const response = await fetch('/api/data') // Backend handles API key authentication
Dependency Injection
Asynchronous Processing
async/awaittry-catch or Error BoundaryPromise<Result>)Format Rules
PascalCase, variables/functions in camelCasesrc/)Clean Code Principles
console.log()Absolute Rule: Every caught error must be logged with context and either re-thrown to Error Boundary, returned as a Result error variant, or displayed as user-facing error state.
Fail-Fast Principle: Fail quickly on errors to prevent continued processing in invalid states
catch (error) {
logger.error('Processing failed', error)
throw error // Handle with Error Boundary or higher layer
}
Result Type Pattern: Express errors with types for explicit handling
type Result<T, E> = { ok: true; value: T } | { ok: false; error: E }
// Example: Express error possibility with types
function parseUser(data: unknown): Result<User, ValidationError> {
if (!isValid(data)) return { ok: false, error: new ValidationError() }
return { ok: true, value: data as User }
}
Custom Error Classes
export class AppError extends Error {
constructor(message: string, public readonly code: string, public readonly statusCode = 500) {
super(message)
this.name = this.constructor.name
}
}
// Purpose-specific: ValidationError(400), ApiError(502), NotFoundError(404)
Layer-Specific Error Handling (React)
Structured Logging and Sensitive Information Protection Redact sensitive fields (password, token, apiKey, secret, creditCard) before logging
Asynchronous Error Handling in React
Basic Policy
Implementation Procedure: Understand Current State → Gradual Changes → Behavior Verification → Final Validation
Priority: Duplicate Code Removal > Large Function Division > Complex Conditional Branch Simplification > Type Safety Improvement
build script and keep under 500KB