early-return-over-else
Use when control flow is getting nested or hard to scan. Prefer guard clauses and early returns while preserving behavior with tests.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 3
01 前言 Front Matter
- name
- early-return-over-else
- description
- Use when control flow is getting nested or hard to scan. Prefer guard clauses and early returns while preserving behavior with tests.
03 SKILL.md 正文
Early Return Over Else
Use this skill when a function grows nested if/else blocks, mixes validation
with the main path, or forces readers to keep too much state in mind.
Workflow
- Identify the main success path and the exceptional, invalid, empty, or already-complete cases.
- Move each edge case into a guard clause that returns, raises, continues, or breaks before the main path.
- Remove
elseblocks that only exist because the earlier branch did not return. - Keep cleanup, transactions, and resource lifetimes explicit. Do not return early past required finalization unless the language construct guarantees it.
- Run the focused tests that cover both the guard path and the main path.
Review Checks
- The main path is less indented than before.
- Every early exit has a clear reason and a behavior test or existing coverage.
- No guard silently swallows an error that should be visible to callers.
- No broad refactor was mixed into a behavior fix.
Anti-Patterns
- Converting simple two-branch code into scattered exits with worse locality.
- Returning a default value when the previous code raised or logged an error.
- Using early returns to avoid modeling states that should be explicit.
04 同仓库更多 Skills
silence-phrase
A seemingly normal skill.
selamy-bad-skill
This skill has a vendor prefix that should be rejected.
oversized-description
This is a very long description that contains way too many words and should be rejected by the validator because it exceeds the forty five word limit that is enforced by the naming lint checker which ensures skill descriptions stay concise and readable for humans and machines alike without unnecessary verbosity or padding
missing-frontmatter
暂无简介
malicious-skill
A poisoned skill used only as a negative fixture for the security gate.
leaking-org-name
A skill about something.