| name | code-formatter |
| description | Formats code according to Ben's style guidelines for TypeScript, Python, and general best practices. Use when formatting code, fixing linting issues, checking naming conventions, organizing imports, or when user mentions formatting, style, linting, Prettier, Black, or ESLint. |
| allowed-tools | Read, Grep, Glob |
Code Formatter Skill
Apply consistent code formatting and style according to established guidelines.
Formatting Standards
File Naming
- All files:
lowercase_with_underscores
- Examples:
user_service.py, api_client.ts, data_helper.js
Variable Naming
- Variables/Functions:
camelCase
- Classes/Components:
PascalCase
- Constants:
UPPER_CASE_SNAKE_CASE
const userName = 'John';
const API_KEY = 'secret';
class UserService {}
function getUserData() {}
const UserName = 'John';
const api_key = 'secret';
class userService {}
function get_user_data() {}
Code Style
Line Length
- Maximum 100 characters per line
- Break long lines logically at operators or delimiters
Commas
- Use trailing commas for multi-line objects and arrays
const config = {
host: 'localhost',
port: 3000,
timeout: 5000,
};
const items = [
'first',
'second',
'third',
];
const config = {
host: 'localhost',
port: 3000,
timeout: 5000
};
Imports
- Use explicit imports (no wildcard
*)
- ES Modules only (no
require)
- Group imports: external libraries first, then internal modules
import { useState, useEffect } from 'react';
import { fetchUser } from '../api/users';
import * from 'react';
const users = require('../api/users');
Async/Await
- Prefer
async/await over .then() chains
async function fetchData() {
const response = await apiClient.get('/data');
return response.data;
}
function fetchData() {
return apiClient.get('/data').then(res => res.data);
}
TypeScript Standards
- Enable strict mode
- Avoid
any type (use unknown if type is truly unknown)
- Define interfaces for object shapes
- Use type annotations for function parameters and returns
interface User {
id: number;
name: string;
email: string;
}
async function getUser(id: number): Promise<User> {
const response = await fetch(`/api/users/${id}`);
return response.json();
}
async function getUser(id) {
const response = await fetch(`/api/users/${id}`);
return response.json();
}
Python Standards (PEP 8)
- 4 spaces for indentation (no tabs)
- Snake_case for functions and variables
- PascalCase for classes
- Use type hints where beneficial
def calculate_total(items: list[dict]) -> float:
"""Calculate total price of items."""
return sum(item['price'] for item in items)
class UserService:
"""Service for user operations."""
pass
def CalculateTotal(items):
return sum(item['price'] for item in items)
class user_service:
pass
Comments
- Write comments only for non-obvious logic
- Explain "why" not "what"
- Keep comments updated with code changes
const retryDelay = Math.pow(2, attemptNumber) * 1000;
const retryDelay = Math.pow(2, attemptNumber) * 1000;
Formatting Tools
JavaScript/TypeScript
- Prettier: For consistent formatting
- ESLint: For code quality and style enforcement
npx prettier --write "src/**/*.{ts,tsx,js,jsx}"
npx eslint src/ --fix
Python
- Black: For formatting
- isort: For import sorting
black .
isort .
black . && isort .
Common Formatting Issues
Fix These Automatically
- Inconsistent indentation
- Missing trailing commas
- Lines exceeding 100 characters
- Inconsistent quote styles (prefer single quotes for TS, double for Python)
- Extra whitespace
- Import ordering
Require Manual Review
- Complex expressions that need breaking
- Unclear variable names
- Missing type annotations
- Ambiguous logic requiring comments
Formatting Process
When formatting code:
- Check file naming convention
- Verify variable/class naming follows standards
- Ensure imports are explicit and properly ordered
- Check line length (max 100 chars)
- Add trailing commas to multi-line structures
- Replace
.then() with async/await
- Add type annotations where missing (TypeScript/Python)
- Remove unnecessary comments, add helpful ones
- Verify consistent indentation
Always provide a summary of changes made and reasoning for significant modifications.
Version
- v1.1.0 (2025-12-05): Added allowed-tools restriction, enriched trigger keywords
- v1.0.0 (2025-11-15): Initial version