$npx -y skills add Archive228/loopkit --skill reduce-nestingFlatten deeply nested conditionals into readable, early-return code. Use on any function with 3+ levels of indentation.
| 1 | # Reduce Nesting |
| 2 | Deep nesting hides bugs in the branches you didn't read. |
| 3 | - **Guard clauses** — handle the invalid/edge cases first and return early. The happy path drops to the left margin. |
| 4 | - **Invert conditions** — `if (!valid) return;` instead of wrapping the whole body in `if (valid) {...}`. |
| 5 | - **Extract** — a nested block doing one thing becomes a named function. |
| 6 | - **Replace flag-then-branch** — return the result directly instead of setting a variable to return later. |
| 7 | Target: no function deeper than 2-3 levels. If you still need more, the function is doing too much — split it. |