skills/benny9193/clean-code/SKILL.md
Clean code principles for readable, maintainable software
npx skillsauth add aiskillstore/marketplace clean-codeInstall 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.
Write code that humans can understand. Code is read far more often than it's written.
// BAD
const d = 86400000; // what is this?
const yyyymmdd = formatDate(date);
const list = getUsers();
// GOOD
const MILLISECONDS_PER_DAY = 86400000;
const formattedDate = formatDate(date);
const users = getUsers();
// BAD - unclear what it does
function handle(data) { }
function process(item) { }
function doIt() { }
// GOOD - verb + noun, describes action
function validateUserInput(input) { }
function calculateTotalPrice(items) { }
function sendWelcomeEmail(user) { }
// BAD
const open = true;
const write = false;
const fruit = true;
// GOOD - is/has/can/should prefix
const isOpen = true;
const canWrite = false;
const hasFruit = true;
// BAD - does too much
function createUserAndSendEmailAndLogActivity(data) {
const user = db.insert(data);
mailer.send(user.email, 'Welcome!');
logger.log(`User ${user.id} created`);
return user;
}
// GOOD - one thing each
function createUser(data) {
return db.insert(data);
}
function sendWelcomeEmail(user) {
mailer.send(user.email, 'Welcome!');
}
function logUserCreation(user) {
logger.log(`User ${user.id} created`);
}
// BAD - too many parameters
function createUser(name, email, age, country, role, department, manager) { }
// GOOD - use object
function createUser(options: CreateUserOptions) { }
interface CreateUserOptions {
name: string;
email: string;
age?: number;
country?: string;
role: Role;
department?: string;
manager?: string;
}
// BAD - boolean changes behavior
function createFile(name: string, temp: boolean) {
if (temp) {
fs.create(`/tmp/${name}`);
} else {
fs.create(name);
}
}
// GOOD - separate functions
function createFile(name: string) {
fs.create(name);
}
function createTempFile(name: string) {
fs.create(`/tmp/${name}`);
}
// BAD - nested conditionals
function getPayAmount(employee) {
let result;
if (employee.isSeparated) {
result = 0;
} else {
if (employee.isRetired) {
result = employee.pension;
} else {
result = employee.salary;
}
}
return result;
}
// GOOD - early returns
function getPayAmount(employee) {
if (employee.isSeparated) return 0;
if (employee.isRetired) return employee.pension;
return employee.salary;
}
// BAD
// Check if employee is eligible for benefits
if ((employee.flags & 0x0F) && (employee.age > 65)) { }
// GOOD - code explains itself
const isEligibleForBenefits = employee.hasHealthPlan && employee.isRetired;
if (isEligibleForBenefits) { }
// Regex matches ISO 8601 date format
const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
// TODO: Refactor when API v2 launches
// WARNING: This must run before database migration
// NOTE: Third-party API has 100ms minimum delay
// BAD
function getUser(id: string): User | null {
return db.find(id) || null;
}
// GOOD - throw or return Result type
function getUser(id: string): User {
const user = db.find(id);
if (!user) throw new UserNotFoundError(id);
return user;
}
// OR use Result type
function getUser(id: string): Result<User, NotFoundError> { }
// BAD
function calculateArea(width: number | null, height: number | null) {
if (width === null || height === null) {
throw new Error('Invalid dimensions');
}
return width * height;
}
// GOOD - require valid inputs
function calculateArea(width: number, height: number) {
return width * height;
}
// BAD - unrelated code together
const user = getUser(id);
const config = loadConfig();
const result = processData(user, config);
logger.log(result);
sendNotification(user);
// GOOD - group related code
const user = getUser(id);
sendNotification(user);
const config = loadConfig();
const result = processData(user, config);
logger.log(result);
| Smell | Problem | Solution | |-------|---------|----------| | Long Method | Hard to understand | Extract methods | | Long Parameter List | Complex interface | Parameter object | | Duplicate Code | Change in multiple places | Extract function | | Dead Code | Confusion, maintenance | Delete it | | Magic Numbers | Unclear meaning | Named constants | | Deep Nesting | Hard to follow | Early returns, extract | | Feature Envy | Wrong location | Move method | | Data Clumps | Always together | Create class |
Leave the code cleaner than you found it.
Every commit should improve code quality slightly. Small, incremental improvements compound over time.
Before committing, ask:
development
Apple Human Interface Guidelines for content display components. Use this skill when the user asks about charts component, collection view, image view, web view, color well, image well, activity view, lockup, data visualization, content display, displaying images, rendering web content, color pickers, or presenting collections of items in Apple apps. Also use when the user says how should I display charts, what's the best way to show images, should I use a web view, how do I build a grid of items, what component shows media, or how do I present a share sheet. Cross-references: hig-foundations for color/typography/accessibility, hig-patterns for data visualization patterns, hig-components-layout for structural containers, hig-platforms for platform-specific component behavior.
tools
Automate HelpDesk tasks via Rube MCP (Composio): list tickets, manage views, use canned responses, and configure custom fields. Always search tools first for current schemas.
testing
Expert Haskell engineer specializing in advanced type systems, pure functional design, and high-reliability software. Use PROACTIVELY for type-level programming, concurrency, and architecture guidance.
tools
GraphQL gives clients exactly the data they need - no more, no less. One endpoint, typed schema, introspection. But the flexibility that makes it powerful also makes it dangerous. Without proper controls, clients can craft queries that bring down your server. This skill covers schema design, resolvers, DataLoader for N+1 prevention, federation for microservices, and client integration with Apollo/urql. Key insight: GraphQL is a contract. The schema is the API documentation. Design it carefully.