skills/refactoring/simplifying-conditionals/SKILL.md
Streamline complex conditional logic using guard clauses, decomposition, and polymorphism. Trigger: When simplifying nested conditionals, replacing switch/if-else chains, or introducing guard clauses.
npx skillsauth add johnnystefan/test-saas-business refactoring/simplifying-conditionalsInstall 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.
This skill enables the agent to streamline complex conditional logic. Conditionals tend to become more complicated over time; these techniques allow an agent to decompose, consolidate, and flatten logic to make it more readable and maintainable.
if-then/else or switch block, extract the condition, the then part, and the else part into separate, well-named methods.break, continue, or return statements.null.// BEFORE: "Arrow" indentation makes the normal flow hard to see
function getPayAmount(): number {
let result: number;
if (isDead) {
result = deadAmount();
} else {
if (isSeparated) {
result = separatedAmount();
} else {
if (isRetired) {
result = retiredAmount();
} else {
result = normalPayAmount();
}
}
}
return result;
}
// AFTER: Guard clauses flatten the method — happy path is obvious
function getPayAmount(): number {
if (isDead) return deadAmount();
if (isSeparated) return separatedAmount();
if (isRetired) return retiredAmount();
return normalPayAmount();
}
// BEFORE: Hard to remember what the complex date check is for
if (date.before(SUMMER_START) || date.after(SUMMER_END)) {
charge = quantity * winterRate + winterServiceCharge;
} else {
charge = quantity * summerRate;
}
// AFTER: Logic is self-explanatory
if (isSummer(date)) {
charge = summerCharge(quantity);
} else {
charge = winterCharge(quantity);
}
function isSummer(date: Date): boolean {
return !date.before(SUMMER_START) && !date.after(SUMMER_END);
}
// BEFORE: Null checks scattered everywhere
const plan = customer === null ? BillingPlan.basic() : customer.getPlan();
// AFTER: Polymorphism handles the "missing" case
class NullCustomer extends Customer {
getPlan() {
return BillingPlan.basic();
}
}
const plan = customer.getPlan(); // Works whether customer is real or NullCustomer
tools
Zustand 5 state management patterns. Trigger: When implementing client-side state with Zustand (stores, selectors, persist middleware, slices).
databases
Zod 4 schema validation patterns. Trigger: When creating or updating Zod v4 schemas for validation/parsing (forms, request payloads, adapters), including v3 -> v4 migration patterns.
development
Vitest unit testing patterns with React Testing Library. Trigger: When writing unit tests for React components, hooks, or utilities.
tools
Vite 8 (Rolldown-powered) build tool configuration, plugin API, SSR, and migration guide. Trigger: When working with vite.config.ts, Vite plugins, building libraries, or SSR apps with Vite.