Run the project's check/lint command after modifying any .ts, .tsx, .js, .jsx file. Skip for docs-only or non-code tasks.
- Use ESLint autofix only for auto-fixable issues (import sorting, etc.)
- Never sort imports manually
- Extract repeated strings into constants
- Extract repeated logic into functions
- If the same value appears 2+ times, it should be a named constant
// Bad
if (status === 'completed') ...
if (status === 'completed') ...
// Good — or better, use a const array + derived type
const isCompleted = status === 'completed'Every meaningful value should be a named constant or derived from config.
// Bad
const fee = amount * 0.003
setTimeout(retry, 5000)
if (tokens.length > 50) paginate()
// Good
const feeRate = 0.003
const fee = amount * feeRate
const retryDelay = convertDuration(5, 's', 'ms')
setTimeout(retry, retryDelay)
const maxTokensPerPage = 50
if (tokens.length > maxTokensPerPage) paginate()Error messages should say what was expected and what was found.
// Bad
ensurePresent(token, 'token')
throw new Error('Invalid input')
// Good
ensurePresent(token, 'selected token for trading pair')
throw new Error(`Expected positive amount, got ${amount}`)Write self-documenting code. Comments only when necessary:
- Complex business logic not obvious from code
- Non-obvious algorithmic decisions
- Temporary workarounds/TODOs with context
Never comment to explain what code does (should be self-explanatory) or restate variable/function names.
// Bad
// Check if user is active
const isActive = user.status === 'active'
// Good — self-explanatory, no comment needed
const isActive = user.status === 'active'
// Good — comment explains non-obvious WHY
// Solana requires 2 extra confirmations during high congestion periods
const confirmations = baseConfirmations + 2Before creating local helpers, check for existing shared utilities in the project's shared/utils or lib directories.
When creating new utilities: search shared first, make generic, place in appropriate category folder.
- Remove all
console.logdebugging before committing - Use proper logging utilities if the project has them
console.errorandconsole.warnare acceptable for genuine runtime warnings
Boolean params are unclear at the call site. Use object params or separate functions.
// Bad — what does `true` mean?
renderToken(token, true)
// Good — self-documenting
renderToken({ token, showPrice: true })
// Good — separate functions for distinct behavior
renderTokenWithPrice(token)
renderTokenCompact(token)