Unused Function/Method Parameter

ID

javascript.unused_method_parameter

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

JavaScript

Tags

code-style, dead-code

Description

Reports formal parameters of a function, method or arrow function that are never referenced inside the function body. Unused trailing parameters add noise to the API and frequently signal that a refactor left arguments behind that nobody passes any more.

The rule uses the after-used semantic: only parameters whose position is greater than that of the last referenced parameter are reported. (a, b, c) ⇒ use(a, c) reports nothing — keeping b preserves c’s position. `(a, b, c) ⇒ use(a) reports b and c.

Rationale

// Bad — `c` is dead weight.
function compute(a, b, c) {
  return a + b;
}

// Bad — same idea, in arrow form.
const sum = (x, y, z) => x + y;

Removing the trailing parameter shortens the signature and avoids implying a contract the function does not honour.

Remediation

Drop trailing unused parameters, or — when the position is required by an external API contract (event handler, callback signature) — prefix the name with _ to mark it as intentionally unused.

// Good — trailing dead weight removed.
function compute(a, b) {
  return a + b;
}

// Good — `_`-prefix marks "kept for the position".
arr.map((_item, index) => index * 2);

// Good — middle position preserved.
function middle(a, b, c) {
  return a + c;
}

Destructuring patterns (function ({a, b}) {}) are out of scope.

References