skills/file-splitting/SKILL.md
Step-by-step guide for breaking large consolidated files into single-function files — naming, exports, import paths, test colocation, and validation. Use when refactoring consolidated utilities or test helpers into modular, maintainable pieces. Do NOT use for creating new files from scratch — this skill is for splitting existing files only.
npx skillsauth add bkinsey808/songshare-effect file-splittingInstall 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.
Depends on: file-organization/SKILL.md — load when naming or import-policy decisions arise. source-refactoring/SKILL.md — load when the split includes broader behavior-preserving refactor work.
docs/file-splitting-reference.md — load on demand for the detailed step-by-step playbook.
Preconditions:
grep or search).docs/ai/rules.md for repo-wide constraints.Clarifying questions:
file-organization skill; colocate tests with source.helpers.ts into per-symbol files — let me know if a different scope was intended."Output format:
Error handling:
No barrel re-exports — do not create index.ts that re-exports the split files.
Preserve JSDoc — carry over all JSDoc comments when moving symbols.
Default export for single-export files — when a new file contains a single
exported function (or class) make that symbol the default export. This
reduces churn at call sites when the symbol is renamed or when the file is
moved, and it matches repository style where single-export modules are
preferred as default exports.
Remove leftover "moved" comments — do not leave behind lines such as
// \\symbol\ moved to ./path after extracting a symbol. Always remove
temporary or human-facing comments that reference the refactor location; if
a reference is useful, add it to the commit message or PR description
instead of leaving it in the codebase.
Split large functions into their own files — if a function is medium or large (subjective, but typically > ~20 or more lines or containing distinct responsibilities), extract it into its own module. Name the file after the function, export the function as the default (single-export modules), and update import sites. This keeps modules small and reviewable and matches the repository's single-export default-export convention.
Quick validation: after splitting, run
git grep -n "\\`\w\+\\` moved to" || true
npm run lint
to ensure no leftover "moved" comments remain and lint passes.
Strict prohibition: do NOT leave "moved" comments in code
Never leave temporary refactor comments in source that state a symbol was
"moved to" another file (for example: // ensureConfigFile moved to ./ensureConfigFile.ts). These lines are forbidden in the codebase and must
be removed before committing. If a migration note is needed for reviewers,
include it in the PR description or commit message instead.
Forbidden pattern (grep for it):
git grep -nE "^\s*//.*\\bmoved to\\b.*$" || true
If this finds any matches, remove them before committing; treat a match as a blocking issue during code review.
Colocate tests — move or create a *.test.ts next to each new source file.
Absolute imports for shared test helpers — use @/ aliases rather than relative paths when helpers are reused across test directories.
No module-level side effects in test helper modules.
Remove the consolidated file once all symbols have been migrated.
npm run test:unit -- path/to/changed.test.ts
npm run lint
Input: "Split shared/src/utils/helpers.ts into separate files"
Expected: Agent reads the file, identifies each exported symbol, creates one file per symbol named after the symbol, updates all import sites, moves or creates colocated tests, removes the original file if empty, runs lint + tsc + targeted tests, reports a bullet list of what moved where.
Input: "Extract the formatDate helper to its own file"
Expected: Agent reads the source file, creates formatDate.ts next to it, moves the function and its JSDoc, updates the one or two import sites, runs validation. Does not create a barrel re-export.
Input: "Split this file" (no file specified) Expected: Agent asks which file to split before proceeding.
docs/ai/rules.md.index.ts re-exports.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.