Loading...
Loading...
Use when writing, fixing, or editing TypeScript with duplicated logic, magic values, unclear one-liners, mixed responsibilities, clutter, arbitrary code, or inconsistent abstraction levels.
npx skill4agent add gosukiwi/clean-code-react clean-typescript-general// Bad - duplication
const taxRate = 0.0825;
const caTotal = subtotal * 1.0825;
const nyTotal = subtotal * 1.07;
// Good - single source of truth
const TAX_RATES: Record<string, number> = { CA: 0.0825, NY: 0.07 };
function calculateTotal(subtotal: number, state: string): number {
return subtotal * (1 + TAX_RATES[state]);
}// Bad - what does this do?
return ((x & 0x0f) << 4) | (y & 0x0f);
// Good - obvious intent
return packCoordinates(x, y);// Bad
if (elapsedTime > 86400) {
// ...
}
// Good
const SECONDS_PER_DAY = 86400;
if (elapsedTime > SECONDS_PER_DAY) {
// ...
}