R02BREAKINGfunctionParameter Reordered
Flags when the positional order of parameters changes. Callers using positional arguments receive wrong values at each argument position.
Applies to
TypeScriptPythonGoJavaRust
Why it matters
Most function calls use positional arguments. If parameters are reordered, callers silently pass values to the wrong parameters. In dynamically typed languages, this causes runtime errors or data corruption. In typed languages, it may catch the mistake — but only if the types differ.
Example
Before
// users.ts
export function createUser(
name: string,
age: number,
email: string
): User { ... }After (parameters reordered)
// users.ts (BREAKING — parameters reordered)
export function createUser(
email: string,
name: string,
age: number
): User { ... }What you see in the terminal
$ npx dg check --staged
[BREAKING] createUser (signature_change)
src/users.ts:8
Parameters were reordered. Callers using positional arguments will pass values incorrectly.How detection works
The classifier checks the intersection of old and new parameter names. For each parameter that exists in both signatures, it compares the index position. If a parameter's position changed, the rule fires.
for (const oldParam of oldSig.params) {
const newParam = newSig.params.find(p => p.name === oldParam.name);
if (newParam) {
const oldIndex = oldSig.params.indexOf(oldParam);
const newIndex = newSig.params.indexOf(newParam);
if (oldIndex !== newIndex) {
// BREAKING: parameter was reordered
}
}
}Real-world scenario
A developer reorders the parameters of `createUser()` to put email first for consistency. All existing callers — `createUser("Alice", 30, "alice@co")` — now pass "Alice" as the email, 30 as the name, and "alice@co" as the age. The function may not crash, but it writes garbage data to the database.
Edge cases
- If all parameters have the same type (e.g., all strings), TypeScript won't catch this
- Named/keyword arguments (Python, Rust struct init) are not affected by reordering
- Reordering + renaming simultaneously triggers both R01 and R02