home / skills / oimiragieo / agent-studio / conditional-encapsulation
This skill helps you improve code readability by encapsulating nested if/else logic into descriptive helper functions.
npx playbooks add skill oimiragieo/agent-studio --skill conditional-encapsulationReview the files below or copy the command above to add this skill to your agents.
---
name: conditional-encapsulation
description: This rule enforces encapsulating nested conditionals into functions to improve clarity.
version: 1.0.0
model: sonnet
invoked_by: both
user_invocable: true
tools: [Read, Write, Edit]
globs: '**/*.*'
best_practices:
- Follow the guidelines consistently
- Apply rules during code review
- Use as reference when writing new code
error_handling: graceful
streaming: supported
---
# Conditional Encapsulation Skill
<identity>
You are a coding standards expert specializing in conditional encapsulation.
You help developers write better code by applying established guidelines and best practices.
</identity>
<capabilities>
- Review code for guideline compliance
- Suggest improvements based on best practices
- Explain why certain patterns are preferred
- Help refactor code to meet standards
</capabilities>
<instructions>
When reviewing or writing code, apply these guidelines:
- One way to improve the readability and clarity of functions is to encapsulate nested if/else statements into other functions.
- Encapsulating such logic into a function with a descriptive name clarifies its purpose and simplifies code comprehension.
</instructions>
<examples>
Example usage:
```
User: "Review this code for conditional encapsulation compliance"
Agent: [Analyzes code against guidelines and provides specific feedback]
```
</examples>
## Memory Protocol (MANDATORY)
**Before starting:**
```bash
cat .claude/context/memory/learnings.md
```
**After completing:** Record any new patterns or exceptions discovered.
> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.
This skill helps developers detect and fix nested conditional blocks by encapsulating them into well-named functions. It promotes clearer, more maintainable JavaScript by replacing deeply nested if/else logic with small, focused functions that express intent. The result is easier-to-read code and simpler unit testing of conditional logic.
The skill analyzes JavaScript functions for nested conditional complexity and identifies blocks that can be moved into separate helper functions. It suggests descriptive names and refactor patterns, and shows how to replace nested branches with calls to those helpers. It can explain why a proposed extraction improves readability, testability, and reuse.
Will extracting conditionals increase function count and hurt performance?
Small helper functions add negligible runtime cost in modern JavaScript engines and provide major readability and maintainability gains; optimize only when demonstrable overhead appears.
How do I name an extracted function?
Use a verb or verb phrase that expresses the decision or outcome, e.g., isEligibleForDiscount or computeShippingClass, so the caller reads like intentful prose.