.agents/skills/code-styleguide/SKILL.md
Universal code style guidelines and principles for writing clean, maintainable code in any programming language. Use when writing or reviewing code, refactoring existing code, conducting code reviews, or establishing coding standards. Focuses on abstraction, KISS principles, SOLID principles, and avoiding over-engineering.
npx skillsauth add hsiangjenli/skills code-styleguideInstall 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.
Universal code style guidelines that promote clean, maintainable, and readable code across all programming languages. These principles focus on simplicity, clarity, and avoiding unnecessary complexity while following proven software engineering best practices.
The simplest solution is usually the best solution.
Good:
def calculate_total_price(items):
total = 0
for item in items:
total += item.price
return total
Avoid:
def calculate_total_price(items):
return sum(item.price for item in items) if items else 0 or reduce(lambda x, y: x + y.price, items, 0)
Each level of abstraction should be consistent and purposeful.
Good:
def process_user_registration():
user_data = validate_input()
user = create_user(user_data)
send_welcome_email(user)
return user
Avoid mixing abstraction levels:
def process_user_registration():
if not email or '@' not in email: # Low-level validation
raise ValueError("Invalid email")
user = User.create(email) # High-level operation
smtp.send(email, "Welcome!") # Medium-level operation
A class should have one, and only one, reason to change.
# Good: Separate concerns
class User:
def __init__(self, email, password):
self.email = email
self.password = password
class UserValidator:
def validate_email(self, email):
return '@' in email and '.' in email
class EmailService:
def send_welcome_email(self, user):
# Email sending logic
Classes should be open for extension, closed for modification.
# Good: Use abstract base classes
from abc import ABC, abstractmethod
class PaymentProcessor(ABC):
@abstractmethod
def process_payment(self, amount):
pass
class CreditCardProcessor(PaymentProcessor):
def process_payment(self, amount):
# Credit card processing logic
class PayPalProcessor(PaymentProcessor):
def process_payment(self, amount):
# PayPal processing logic
Objects of a superclass should be replaceable with objects of a subclass.
Clients should not be forced to depend on interfaces they don't use.
Depend on abstractions, not concretions.
Don't build what you don't need right now.
Good (simple and direct):
class ConfigManager:
def __init__(self, config_file):
with open(config_file) as f:
self.config = json.load(f)
def get(self, key):
return self.config.get(key)
Over-engineered:
class AbstractConfigurationStrategy(ABC):
@abstractmethod
def load_configuration(self): pass
class JSONConfigurationStrategy(AbstractConfigurationStrategy):
# ... complex factory pattern implementation
class ConfigurationManager:
def __init__(self, strategy: AbstractConfigurationStrategy):
self.strategy = strategy
# ... unnecessary abstractions for a simple config reader
Code should be self-documenting. Documentation is supplementary, not primary.
Good:
def calculate_discount(price: float, customer_type: str) -> float:
"""Calculate discount based on customer type.
Args:
price: Original price
customer_type: One of 'regular', 'premium', 'vip'
Returns:
Discounted price
"""
discounts = {'regular': 0, 'premium': 0.1, 'vip': 0.2}
return price * (1 - discounts.get(customer_type, 0))
Avoid:
Good:
user_count = len(users)
is_valid_email = validate_email(email)
for user_index in range(user_count):
Avoid:
uc = len(u)
flag = check(e)
for i in range(uc):
is_, has_, can_ prefixesGood:
def process_order(order):
if not order.is_valid():
return None
if not order.has_payment():
return None
return fulfill_order(order)
Avoid:
def process_order(order):
if order.is_valid():
if order.has_payment():
# deep nesting continues...
return fulfill_order(order)
else:
return None
else:
return None
# Good: Specific and clear
class InvalidEmailError(ValueError):
def __init__(self, email):
super().__init__(f"Invalid email format: {email}")
def validate_email(email):
if '@' not in email:
raise InvalidEmailError(email)
Write self-documenting code first. Documentation lives in the code.
Good comments explain intent:
# Retry up to 3 times to handle transient network issues
def fetch_user_data(user_id, max_retries=3):
Avoid obvious comments:
# Increment counter by 1
counter += 1
Avoid emoji decorations:
# Bad: Don't do this
# ✅ Success! This function works!
# 🚀 Super fast implementation
# ⚠️ Warning: Check this
# Good: Clear, professional comments
# Returns None if validation fails
# Optimized for large datasets
# Validates input before processing
def test_should_reject_user_with_invalid_email():
invalid_email = "not-an-email"
with pytest.raises(InvalidEmailError):
create_user(email=invalid_email)
Use this skill when:
Key decision points:
When generating or modifying code:
Minimize file generation:
No emoji in output:
Self-documenting code over documents:
Good output structure:
project/
├── src/
│ ├── main.py # Main code
│ └── utils.py # Helper functions
├── tests/
│ └── test_main.py # Tests
└── README.md # One README only
Avoid:
project/
├── src/
│ ├── main.py
│ └── utils.py
├── docs/
│ ├── CHANGES.md # Unnecessary
│ ├── SUMMARY.md # Unnecessary
│ └── API_GUIDE.md # Unnecessary
├── README.md
└── NOTES.md # Unnecessary
development
Write or rewrite a LinkedIn About section with a recruiter-friendly four-part structure: positioning, value proposition, career goals, and call to action. Use when the user wants a stronger LinkedIn self-introduction, personal branding summary, or About draft tailored to job search goals.
tools
Manage local or remote ICS calendar sources to inspect upcoming meetings, summarize work hours, and add, update, or delete calendar events when users need a quick operational view of their schedule.
tools
Use mise as the default workflow for installing programming language runtimes, CLIs, and switching tool versions. Trigger this whenever the user needs a new development environment, hits a version mismatch, wants to align local and global toolchains, or asks how to install a language or CLI without using nvm, pyenv, asdf, brew-only flows, or ad-hoc installers.
development
Create educational and technical presentation slides with structured layouts including covers, table of contents, section dividers, and key takeaways. Use when building technical tutorials, workshops, or educational content with Slidev.