lightsoutAlpha

object-args

How a function takes its arguments.

Agent checkAdvises by default

The rule

Agents read this text as written when they write and review code.

Give a function that takes arguments one object argument, and destructure it:

  • An exported function declares an interface named Params for it.
  • A private helper uses an inline object type, since one file cannot declare two Params.
  • A function with no arguments takes no object and has no Params.

Two signatures follow a contract set elsewhere, and are never declared again locally: a callback, whose caller sets its shape, and a wrapper that passes its params object on unchanged, typed Parameters<typeof callee>[0].

When callers need to name the argument type, export it as a named type in place of Params.

Positional arguments decay as a function grows: new ones are added out of order, and two of one type swap silently (copyFile(dest, src) compiles). A named argument says what it is at every call.

Examples

The agent flags code like the incorrect example and accepts code like the correct one.

Incorrect

src/files/copyFile.ts
// Two same-typed slots in a row: `copyFile(dest, src)` compiles just as happily
// as the intended order, and no call site says which is which.
export const copyFile = (sourcePath: string, destPath: string, overwrite = false): string =>
`${sourcePath} -> ${destPath}${overwrite ? ' (overwrite)' : ''}`;

Correct

src/files/copyFile.ts
interface Params {
sourcePath: string;
destPath: string;
overwrite?: boolean;
}
// The same call, self-documenting at every site, and safe to grow.
export const copyFile = ({ sourcePath, destPath, overwrite = false }: Params): string =>
`${sourcePath} -> ${destPath}${overwrite ? ' (overwrite)' : ''}`;

Configure

  • Block"blocking"Stops a run when a file the run changed breaks the rule.
  • Advise"advisory"Reports it and hands it to the refactor agent. Never stops a run.
    Default
  • Off"off"Not checked. Use it when your own linter already enforces the rule.

Add this to your lightsout.config.json, then change the value.

lightsout.config.json
{
"standards-rule-settings": {
"object-args": "advisory"
}
}

Packs that select it