modrexio/modrex / .agents/skills/control-flow
control-flow
UnverifiedFlatten nested conditionals and make the happy path readable
control-flow
Use this skill when a change touches branching logic, validation, installation flow, filesystem routing, renderer event handlers, or any function with nested conditionals.
This skill targets dangerous pattern #4 from .agents/rules/ai-danger-patterns.md: deep if/else nesting.
Rule
The happy path should not be buried.
Invalid, unsupported, or exceptional cases should exit early.
Required checks
Look for:
- nested
if/elseblocks elseafterreturn,throw,continue, orbreak- repeated checks for the same condition
- validation mixed with business logic
- side effects hidden inside deep branches
- boolean expressions that need a name
Refactoring order
Try these in order:
- invert the condition and return early
- remove
elseafter terminal statements - extract a named boolean
- extract a small helper only when it names a real domain concept
- split the workflow into smaller functions
- use
switchfor many exclusive domain cases
Examples
Bad:
if (game.isInstalled) {
if (game.supportsMods) {
if (!game.isRunning) {
installMod(mod)
}
}
}
Good:
if (!game.isInstalled) return
if (!game.supportsMods) return
if (game.isRunning) return
installMod(mod)
Bad:
if (!gamePath) {
return null
} else {
return scanGame(gamePath)
}
Good:
if (!gamePath) return null
return scanGame(gamePath)
Preserve behavior
Do not change behavior while flattening code.
Before editing, identify which branches return early, throw, mutate state, write files, call APIs, or show UI feedback. After editing, ensure those effects still happen under the same conditions.
Warning
Do not fix nesting by creating a fake abstraction.
Bad:
function validateGameState(game: Game) {
return game.isInstalled && game.supportsMods && !game.isRunning
}
Only good if validateGameState is a real reused domain rule. Otherwise use a named boolean inline.
Report
After editing, report:
- which function or file was flattened
- whether behavior was preserved
- which check was run, if any
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |