AgentSkillsCN

clean-functions

在编写、修复、编辑或重构 TypeScript 函数时使用此技能。严格遵循“整洁代码”原则——单个函数参数不超过 3 个,确保单一职责,杜绝标志位参数。

SKILL.md
--- frontmatter
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.

Clean Functions

F1: Too Many Arguments (Maximum 3)

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

// Good - use an interface or type
interface UserData {
    name: string;
    email: string;
    age: number;
    country: string;
    timezone: string;
    language: string;
    newsletter: boolean;
}

const createUser = (data: UserData): User => {
    // ...
};

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.

typescript
// Bad - modifies argument
function appendFooter(report: string[]): void {
    report.push("\n---\nGenerated by System");
}

// Good - returns new value
const withFooter = (report: string): string => {
    return report + "\n---\nGenerated by System";
};

F3: No Flag Arguments

Boolean flags mean your function does at least two things.

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

// Good - split into two functions
const renderTestPage = (): void => { /* ... */ };
const renderProductionPage = (): void => { /* ... */ };

F4: Delete Dead Functions

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