Skip to content

misplaced-argument ​

An argument named after another parameter of the function it is passed to, and not after its own: corner(x, y, 1.05) for corner(size, x, y, margin), area(height, width) for area(width, height). On by default, as a warning.

Why: a parameter inserted in front of others of the same type, or two arguments swapped, still type-checks: every argument has the type its parameter wants. The names say what happened: the value called x lands in the parameter called size, while the function has a parameter called x one place on. An agent that adds a parameter updates the calls it sees; the call it doesn't see keeps its old arguments, and draws in the wrong place.

❌ Rejected: a parameter was inserted in front, and this call kept its arguments

✕ Rejectedmisplaced-argument
ts
function corner(size: number, x: number, y: number, margin = 1): readonly [number, number] {
  return [x * size * margin, y * size * margin];
}

export function frame(size: number, x: number, y: number): readonly [number, number] {
  return corner(x, y, 1.05);
}
text
`x` goes to `size` (parameter 1), not to `x` (parameter 2); `y` goes to `x` (parameter 2), not to
`y` (parameter 3): the argument is named after another parameter of `corner`, as if a parameter
was inserted or two were swapped
  = help: Pass each argument where its parameter is (`corner(size, x, y, margin)`), or, if the
    value really is what the parameter it lands in means, name it so

✅ Accepted: each argument where its parameter is

✓ Accepted0 diagnostics
ts
function corner(size: number, x: number, y: number, margin = 1): readonly [number, number] {
  return [x * size * margin, y * size * margin];
}

export function frame(size: number, x: number, y: number): readonly [number, number] {
  return corner(size, x, y, 1.05);
}

❌ Rejected: where it goes and where it comes from, swapped

✕ Rejectedmisplaced-argument
ts
import { type Mut, mut } from "@evobug_com/safe-ts-std/mut";

function copyInto(target: Mut<number[]>, source: readonly number[]): void {
  for (const value of source) target.push(value);
}

export function refill(): readonly number[] {
  const target: number[] = [];
  const source = [1, 2, 3];
  copyInto(mut(source), target);
  return target;
}
ts
import { type Mut, mut } from "@evobug_com/safe-ts-std/mut";

function copyInto(target: Mut<number[]>, source: readonly number[]): void {
  for (const value of source) target.push(value);
}

export function refill(): readonly number[] {
  const target: number[] = [];
  const source = [1, 2, 3];
  copyInto(source, target);
  return target;
}

❌ Rejected: two arguments swapped

✕ Rejectedmisplaced-argument
ts
function area(width: number, height: number): number {
  return width * height;
}

export function room(width: number, height: number): number {
  return area(height, width);
}

✅ Accepted: an object makes the order not matter

✓ Accepted0 diagnostics
ts
function area(size: { readonly width: number; readonly height: number }): number {
  return size.width * size.height;
}

export function room(width: number, height: number): number {
  return area({ width, height });
}

What counts ​

An argument is named by what it is written as: a binding (x), the last name of a member (pos.x, this.x, box.#x), or what a loan lends (mut(source), mutEach(items)). The call is resolved to the function it runs, as the call graph resolves calls (a function, a method, a constructor and its parameter properties, a function reached through a field or an import), and it is reported when:

  • an argument's name is the name of another parameter of that function, not of its own (case and a leading _ or $ aside);
  • those two parameters are declared with the same type as a call sees it: the written types opened (aliases, interfaces), with what a call lets through taken off (readonly, Readonly<T>, ReadonlyArray<T>, ReadonlyMap, ReadonlySet, Mut<T>), so that copy(source, target) for copy(target: Mut<number[]>, source: readonly number[]) counts. Where they differ, TypeScript checked the argument against its own parameter, and the name is a coincidence;
  • no other argument of the call is written with the same name (area(p.x, q.x), corner(1, x, x));
  • and the misplaced arguments form a shift or a swap: two or more, each landing the same number of places early (a parameter inserted in front of them), or pairs that took each other's places.

Not reported:

  • A function calling itself (gcd(b, a % b)): it reorders its own parameters on purpose.
  • Both orders in one function: ranks(left, right) || -ranks(right, left), a symmetric check.
  • a and b, which name a place in a list of arguments (the first, the second), not a meaning: turn(a, b, c) for turn(pivot, a, b).

A warning, not an error: a swap can be meant (a function of two points called with them the other way round), and the names are the only evidence.

What the rule can't see ​

  • Functions it doesn't resolve: the language's built-ins, the platform's and the packages' (Math.atan2(x, y) for atan2(y, x)): their parameter names are in their declarations, which the rule doesn't read.
  • Arguments with no name: a literal, an expression (x + 1), a call. A shift of literals (corner(16, 1.05) after a parameter was added) has nothing to compare.
  • One argument out of place with nothing else moved (lerp(b, c, t) for lerp(a, b, t)): as often a name for another thing as a mistake, so not reported.
  • Destructured and rest parameters have no name to compare, and an argument after a spread has no known position.
  • Names that don't match: corner(px, py) for corner(size, x, y) is the same bug; so is an argument kept in a const of another name first (const h = box.height; area(h, w)): the rule reads the name the argument is written with.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra