R03BREAKINGfunction

Required Parameter Added

Flags when a new required parameter is added to a function. All existing callers are missing the new argument and will fail to compile or crash at runtime.


Applies to

TypeScriptPythonGoJavaRust

Why it matters

Adding a required parameter means every single call site must be updated. In a large codebase, this could be hundreds of files. Miss one, and you get a compilation error (typed languages) or a runtime undefined (JavaScript).

Example

Before
// auth.ts
export function authenticate(
  token: string
): AuthResult { ... }
After (new required param)
// auth.ts (BREAKING)
export function authenticate(
  token: string,
  tenantId: string  // NEW required parameter
): AuthResult { ... }

What you see in the terminal

$ npx dg compare main feature/multi-tenant

  [BREAKING] authenticate (signature_change)
  src/auth.ts:5
  Required parameter 'tenantId' was added. All existing callers will fail.

  Affected call sites (12):
    X  src/middleware/auth.ts:23 -- provides 1 arg(s), needs 2
    X  src/routes/login.ts:45 -- provides 1 arg(s), needs 2
    ...and 10 more

How detection works

The classifier counts the number of required parameters in both signatures. If the new signature has more required parameters than the old one, the rule fires.

const oldRequired = oldSig.params.filter(p => !p.optional && !p.defaultValue);
const newRequired = newSig.params.filter(p => !p.optional && !p.defaultValue);
if (newRequired.length > oldRequired.length) {
  // BREAKING: new required parameter added
}

Real-world scenario

A team adds multi-tenant support by requiring a `tenantId` parameter on the `authenticate()` function. Every middleware, route handler, and test file that calls this function — potentially dozens of files — must be updated. The call-site tracer shows exactly which files are affected and how many arguments each provides.

Edge cases

  • Adding a parameter with a default value is R05 (safe), not R03
  • Adding an optional parameter (?) is R05 (safe), not R03
  • Adding a REST parameter (...args) is R14 (warning), not R03