Too Many Function Parameters
ID |
javascript.max_params |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Complexity |
Language |
JavaScript |
Tags |
code-style, complexity |
Description
Reports a function whose parameter count exceeds the configured threshold (default 7):
// Bad — eight positional parameters.
function process(a, b, c, d, e, f, g, h) { ... } // FLAW
// Good — single options object.
function process(opts) { ... }
Rationale
A function with many positional parameters is hard to call correctly — readers have to remember the order, and arguments of the same primitive type ((string, string, string)) are easy to mix up. High parameter counts also signal that the function has accumulated unrelated responsibilities; the cure is usually to extract subgroups into objects or split the function.
The threshold is intentionally a guideline, not a hard limit — different teams settle on different numbers. The default of 7 is a forgiving baseline that still catches the worst offenders; tighten it (3 or 4) for stricter code-style enforcement.
Remediation
Pick the cure that matches the call shape:
// Options object — best when callers want named arguments.
function process({ name, count, retries = 3, timeout = 1000 } = {}) { ... }
// Split the function.
function buildMessage(name, count) { ... }
function send(message, retries, timeout) { ... }
// Partial application / curry.
const sendWithDefaults = (msg) => send(msg, 3, 1000);