| name | best-practices |
| description | Use when refactoring or implementing features - validation, component design, API research |
Best Practices
Use this skill when implementing features or refactoring code to follow established patterns.
Checklist
Validation Before Claiming Success
Question Patterns Before Copying
When copying code from elsewhere in the codebase:
Refactoring Guidelines
Examples:
export const ImageGrid: FC<{ images: Image[] }> = ({ images }) => {
const baseURL = useBackendUrl()
return <div>{/* render images with baseURL */}</div>
}
export const ImageGrid: FC<{ images: Image[]; baseURL: string }> = ({
images,
baseURL
}) => {
return <div>{/* render images */}</div>
}
Extract Duplicated Configuration
Example:
const options = { timeout: 5000, retries: 3 }
const options = { timeout: 5000, retries: 3 }
export const API_OPTIONS = { timeout: 5000, retries: 3 }
import { API_OPTIONS } from './constants'
Verify API Behavior Before Refactoring
Example:
const value = api.getValue()
if (value === null || value === undefined || value === '') {
}
try {
const value = api.getValue()
} catch (error) {
}
Research First
Common Pitfalls
Over-validation:
- Don't add checks for impossible states
- Trust internal APIs and framework guarantees
- Only validate at system boundaries (user input, external APIs)
Premature abstraction:
- Don't create helpers for one-time operations
- Don't design for hypothetical future requirements
- Three similar lines is better than premature abstraction
Ignoring performance:
- Tests passing ≠ code is performant
- Check re-render count, bundle size, load times
- Profile before and after changes
Reference
See @docs/CODING_STYLE.md for detailed coding standards.