| name | clean-functions |
| description | Use when writing, fixing, editing, or refactoring TypeScript functions. Enforces Clean Code principles—maximum 3 arguments, single responsibility, no flag parameters. |
| when_to_use | Also trigger on: functions (or React components) with 4+ parameters/props, boolean flag parameters like `isTest`, functions that mutate their parameters (e.g. push to an input array), unused exports or dead helper functions, or asks like "too many props", "split this function", "is this still used".
|
Clean Functions
F1: Too Many Arguments (Maximum 3)
function createUser(
name: string,
email: string,
age: number,
country: string,
timezone: string,
language: string,
newsletter: boolean
) {
}
type UserData = {
name: string;
email: string;
age: number;
country: string;
timezone: string;
language: string;
newsletter: boolean;
};
function createUser(data: UserData) {
}
More than 3 arguments means your function is doing too much or needs
a data structure.
F2: No Output Arguments
Don't modify arguments as side effects. Return values instead.
type Report = {
content: string;
};
function appendFooter(report: Report): void {
report.content += "\n---\nGenerated by System";
}
function withFooter(report: Report): Report {
return {
...report,
content: `${report.content}\n---\nGenerated by System`,
};
}
F3: No Flag Arguments
Boolean flags mean your function does at least two things.
function render(isTest: boolean) {
if (isTest) {
renderTestPage();
} else {
renderProductionPage();
}
}
function renderTestPage() {}
function renderProductionPage() {}
F4: Delete Dead Functions
If it's not called, delete it. No "just in case" code. Git preserves history.