skills/source-refactoring/SKILL.md
Patterns for splitting functions and components into their own files. Ensures consistent exports, JSDoc preservation, and test colocation. Use when refactoring large files or extracting reusable logic.
npx skillsauth add bkinsey808/songshare-effect source-refactoringInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Requires: file-read, terminal (linting/testing). No network access needed.
Use this skill when:
Execution workflow:
npm run lint.Output requirements:
If the new file only exports one main function or component, use export default:
// ✅ GOOD: Single exported function
/**
* @param value - The value to check
* @returns True if value is a record
*/
export default function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
If the file needs to export multiple related symbols (e.g., related types or small helpers that don't merit their own files), use named exports or a combination:
// ✅ GOOD: Multiple related exports
export type FooProps = { ... };
export function Foo() { ... }
Note: If the file ONLY exports one thing, it MUST be export default.
When extracting test helpers, utilities, or shared modules that will be imported from multiple locations, use absolute paths (@/) to ensure the helper works regardless of the caller's directory depth.
Why: Relative paths (../../../) break when tests or modules move to different directory levels. Absolute paths (@/react/event/manage/helpers) remain stable.
// ❌ BAD: Relative path breaks from different caller locations
vi.doMock("../slide/useSlideManagerView", () => ({ default: mockFn }));
// ✅ GOOD: Absolute path works from any location
vi.doMock("@/react/event/manage/slide/useSlideManagerView", () => ({ default: mockFn }));
For test helper files created during refactoring, always use absolute imports if the helper will be shared across multiple test suites.
Test helper files should export callable setup functions, not auto-execute at import time. Use vi.hoisted() for shared mock state.
See unit-test-best-practices skill for full mocking patterns and examples.
Always copy the JSDoc comments from the original file to the new file. Ensure parameters and return descriptions are accurate. Do not include types in JSDoc for TypeScript files.
If the symbol being moved has existing tests, they must be moved to a new test file colocated with the source.
NewFile.test.ts next to NewFile.ts.it/describe blocks from the old test file to the new one.Search the codebase for all occurrences of the moved symbol and update their imports.
import { symbol } from './Original' to import symbol from './New'.@/react/event/manage/test-utils/mockUseSlideManagerView.test-util). Also follow the convention of naming helper files with a .test-util.ts[x] suffix so their purpose is obvious.NewFile.tsx or NewFile.ts in the appropriate directory.export default if it's the only export.OriginalFile.test.ts).NewFile.test.ts.grep_search or semantic_search to find all usages and update imports.npm run lint and npm run test:unit -- <NewFile>.test.ts to confirm the change is correct.docs/ai/rules.md.file-splitting.naming-conventions.tools
Zustand state management patterns for this project — store creation, selectors, Immer middleware, async actions with loading states, devtools, persist, and testing. Use when authoring or editing Zustand stores (use*Store files) or components that subscribe to stores. Do NOT use for React component structure or TypeScript-only utilities.
testing
How to write, update, or split skill files in this repo. Use when creating a new SKILL.md, updating an existing one, or deciding whether to put content in a skill vs. docs/.
development
Complete guide for testing React hooks — renderHook, Documentation by Harness, installStore, fixtures, subscription patterns, lint/compiler traps, and pre-completion checklist. Read docs/testing/unit-test-hook-best-practices.md for the full reference.
development
Vitest unit test authoring for this repo — setup, mocking, API handler testing, and common pitfalls for non-hook code. Use when the user asks to add, update, fix, or review unit tests for utilities, components, API handlers, or scripts. Do NOT use for React hook tests — load unit-test-hook-best-practices instead.