limit-function-arguments
Installation
SKILL.md
Summary
Functions should ideally have 0 to 2 arguments, and at most 3. If a function requires more than 3 arguments, group them into a single Object, Interface, or Struct (often called "Options Object" or "Named Parameters").
Rationale
- Readability: A call like
createUser(name, true, false, 5)is ambiguous.createUser({ name, isAdmin: true, ... })is self-documenting. - Order Safety: Positional arguments are prone to off-by-one errors or swapped values (e.g.,
widthvsheight). - Extensibility: Adding a new field to an options object does not break the function signature for existing callers.
Guidance
- Count Rule:
- 0-2 args: Great.
- 3 args: Acceptable.
- 4+ args: Refactor to use an Object/Struct.
- Grouping:
- Identify related arguments and group them (e.g.,
x, y, z->Vector3).
- Identify related arguments and group them (e.g.,
- Language Specifics:
- TS/JS: Use destructuring in the signature.
function foo({ a, b }: Options). - Go: Use a
Configstruct.func NewServer(cfg Config).
- TS/JS: Use destructuring in the signature.