# Clean Functions

> Use when writing, fixing, editing, or refactoring TypeScript functions. Enforces Clean Code principles—maximum 3 arguments, single responsibility, no flag parameters.

- Skill: `ertugrul-dmr/clean-functions-2` (Agent Skill)
- Install (CLI): `npx skillmds@latest add ertugrul-dmr/clean-functions-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ertugrul-dmr/clean-functions-2/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: ertugrul-dmr (https://skillmd.com/u/ertugrul-dmr)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/ertugrul-dmr/clean-functions-2

---


# Clean Functions

## F1: Too Many Arguments (Maximum 3)

```ts
// Bad - too many parameters
function createUser(
  name: string,
  email: string,
  age: number,
  country: string,
  timezone: string,
  language: string,
  newsletter: boolean
) {
  // ...
}

// Good - use a typed object
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.

```ts
type Report = {
  content: string;
};

// Bad - modifies argument
function appendFooter(report: Report): void {
  report.content += "\n---\nGenerated by System";
}

// Good - returns new value
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.

```ts
// Bad - function does two different things
function render(isTest: boolean) {
  if (isTest) {
    renderTestPage();
  } else {
    renderProductionPage();
  }
}

// Good - split into two functions
function renderTestPage() {}
function renderProductionPage() {}
```

## F4: Delete Dead Functions

If it's not called, delete it. No "just in case" code. Git preserves history.

