oxc-project/oxc · warning · OxcDiagnostic
Function has too many parameters ({}). Maximum allowed is {}
Error message
Function has too many parameters ({}). Maximum allowed is {}. What it means
The anonymous-function variant of `max-params`. Identical semantics to the named variant — parameter count exceeds `max` (default 3) — but the message template says "Function has too many parameters" because the diagnostic cannot anchor a name (anonymous function expression or IIFE). Produced by the same `max_params_diagnostic` helper at crates/oxc_linter/src/rules/eslint/max_params.rs:19.
Source
Thrown at crates/oxc_linter/src/rules/eslint/max_params.rs:19
use oxc_ast::{
AstKind,
ast::{TSFunctionType, TSType},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;
use serde::Deserialize;
use serde_json::Value;
use crate::{
AstNode,
context::LintContext,
rule::{DefaultRuleConfig, Rule},
};
fn max_params_diagnostic(message: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(message.to_string())
.with_help(
"This rule enforces a maximum number of parameters allowed in function definitions.",
)
.with_label(span)
}
#[derive(Debug, Default, Clone, Deserialize)]
pub struct MaxParams(Box<MaxParamsConfig>);
#[derive(Debug, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct MaxParamsConfig {
/// Maximum number of parameters allowed in function definitions.
#[serde(alias = "maximum")]
max: u32,
/// This option controls when to count a `this` parameter.
///
/// - "always": always count `this`View on GitHub (pinned to e1e7af627c)
Solutions
- Wrap multi-arg callbacks in a named helper that takes an options/aggregate argument, or destructure: `.reduce((acc, { value, index }) => ...)`.
- Increase `max` to 4 in config to accommodate standard array-callback signatures like reduce's.
- Convert the anonymous function into a named function with an options object so the signature is explicit and greppable.
Example fix
// before
const total = items.reduce(function (acc, item, index, array) {
return acc + item.price * (index < array.length - 1 ? 1 : 0.9);
}, 0);
// after
const total = items.reduce((acc, item, index, array) =>
acc + item.price * (index < array.length - 1 ? 1 : 0.9), 0); Defensive patterns
Strategy: validation
Validate before calling
// Validate callback arity before passing it, especially for reduce (4 spec params):
// config: { "max-params": ["error", 4] } accommodates standard array callbacks.
// oxlint src/ gates the PR. Prevention
- Know each array method's callback signature: reduce takes 4 (acc, value, index, array) — configure max >= 4 if you use the full form.
- Omit unused trailing callback parameters instead of declaring them.
- Prefer destructuring in the callback parameter to keep the count low and the intent explicit.
When it happens
Trigger: Anonymous function expressions passed as callbacks with 4+ parameters: `array.reduce((acc, item, idx, arr, extra) => ...)` under a max of 3 (note reduce's own callback takes up to 4 by spec), `request('/x', function (err, res, body, next) {})`, or multi-arg IIFEs. Counting includes rest/default params.
Common situations: Array method callbacks whose spec-defined signatures already consume the budget (reduce has 4 params: accumulator, value, index, array); jQuery-style multi-argument callbacks; strict max configs (2) combined with reduce/map callbacks; anonymous middleware functions in Express-style stacks.
Related errors
- Function '{}' has too many parameters ({}). Maximum allowed
- Default parameters should be last
- Arrow function has too many parameters ({}). Maximum allowed
- function has too many statements ({count}). Maximum allowed
- {name} has a complexity of {complexity}. Maximum allowed is
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/aadec5a02d62abe2.
Report an issue: GitHub.