← ClaudeAtlas

spaghetti-rwdlisted

Apply this skill when the user asks to "разобрать спагетti", "разбить функцию", "переделать спагетти", decompose a monolithic function, or activates via @spaghetti or "разбей по RWD". Splits a single sprawling function into a chain of single-responsibility steps sharing one state object, run through a common step-runner. Do NOT apply without explicit activation — this changes control flow, not just naming.
InExSu/claude-skills · ★ 0 · AI & Automation · score 75
Install: claude install-skill InExSu/claude-skills
# Spaghetti Refactor (RWD pattern) ## Core Principle One monolithic function = many hidden responsibilities glued together with shared local variables and nested `if`s. Refactor by: 1. Pulling every distinct responsibility into its own function. 2. Passing a single shared state object (`ns`) between them instead of local variables. 3. Each step function **mutates `ns`** and returns nothing (or returns early via guard clause). 4. Replacing nested `if` blocks with guard clauses (`if (!x) { ...; return }`). 5. Chaining the steps through one orchestrator function that calls each step via a common runner (`rwd`), in order. ## What counts as "one responsibility" Split whenever the code: - fetches/reads something (sheet, file, API, DB) → own step - validates/guards a precondition → folded into the step that needs it, as an early return, not a separate step unless validation is reused - transforms/builds data → own step - reports/logs → own step - writes/persists → own step Rule of thumb: if you can describe the block in one short verb phrase ("get sheet", "read header", "build rows", "log result"), it's a candidate step. ## Step function shape ```js function <verb><Noun>_RWD(ns) { // read whatever it needs from ns // guard clauses first, with early return if (!ns.something) { ns.somethingElse = <safe empty value> return } // do exactly one thing ns.<field> = <result> } ``` Rules: - Name = `verb + Noun + _RWD` (e.g. `getResultSheet_RWD`, `buildResul