oxc-project/oxc · warning · OxcDiagnostic
Function '{}' has too many parameters ({}). Maximum allowed
Error message
Function '{}' has too many parameters ({}). Maximum allowed is {}. What it means
The named-function variant of the `max-params` diagnostic. The rule counts a function's parameters (including default/rest parameters) and reports when the count exceeds `max`, defaulting to 3 with optional `countThis`/`countVoidThis` semantics (crates/oxc_linter/src/rules/eslint/max_params.rs:68-71). This message template includes the function's name (e.g. `Function 'createUser' has too many parameters (5). Maximum allowed is 3.`). The diagnostic is built 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
- Group related parameters into an options object: `function transform(input, { options, logger, cache, flags })` — keeps call sites self-documenting.
- Raise the limit via config `{ "max-params": ["error", 5] }` if the team accepts wider signatures.
- Use a builder or config-carrying struct/class when many parameters are genuinely independent.
Example fix
// before
function createUser(name, email, role, team, sendWelcome, audit) { /* ... */ }
// after
function createUser(
name,
{ email, role = 'member', team, sendWelcome = true, audit } = {},
) { /* ... */ } Defensive patterns
Strategy: validation
Validate before calling
// CI gate: oxlint --rule max-params=3 src/ // Signature check before review: count positional params; >3 -> switch to an options object.
Type guard
// Narrowing-style guard for config-style calls (TypeScript):
type CreateUserOptions = { email: string; role?: string; team?: string };
function createUser(name: string, opts: CreateUserOptions) { /* ... */ } Prevention
- Default to (subject, options-object) signatures for anything with more than two inputs.
- When a parameter must be added, ask whether it belongs to a config object instead of position four-plus.
- Rest params count as one — but do not abuse `...args` to dodge the rule; it hides the real signature.
When it happens
Trigger: Declare a named function, method, or function declaration with more parameters than `max`: `function transform(input, options, logger, cache, flags) {}` (5 > 3 default). `this` parameters are ignored unless `countThis` is enabled; a lone `void this` marker is never counted.
Common situations: Functions that grew one flag at a time during feature work; positional configuration APIs predating an options-object refactor; test factories with many optional arguments; enabling the rule with default max 3 across a mature codebase produces many reports at once.
Related errors
- Function has too many parameters ({}). Maximum allowed is {}
- Default parameters should be last
- Arrow function has too many parameters ({}). Maximum allowed
- {name} has a complexity of {complexity}. Maximum allowed is
- Blocks are nested too deeply ({num}). Maximum allowed is {ma
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/32233e9a3b64d82c.
Report an issue: GitHub.