oxc-project/oxc · warning · OxcDiagnostic
function has too many statements ({count}). Maximum allowed
Error message
function has too many statements ({count}). Maximum allowed is {max}. What it means
The anonymous variant of `max-statements`: the function body exceeds the statement budget (default 10) and the diagnostic cannot resolve a name, so the message reads "function has too many statements". Built by the same `max_statements_diagnostic` at crates/oxc_linter/src/rules/eslint/max_statements.rs:31 choosing the `None`-name branch. Configuration (`max`, `ignoreTopLevelFunctions`) is shared with the named variant.
Source
Thrown at crates/oxc_linter/src/rules/eslint/max_statements.rs:31
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::{context::LintContext, rule::Rule};
fn max_statements_diagnostic(
name: Option<&str>,
count: u32,
max: u32,
span: Span,
) -> OxcDiagnostic {
let message = if let Some(name) = name {
format!("function `{name}` has too many statements ({count}). Maximum allowed is {max}.")
} else {
format!("function has too many statements ({count}). Maximum allowed is {max}.")
};
OxcDiagnostic::warn(message)
.with_help("Consider splitting it into smaller functions.")
.with_label(span)
}
const DEFAULT_MAX_STATEMENTS: u32 = 10;
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct MaxStatementsConfig {
/// Maximum number of statements allowed per function.
max: u32,
/// Whether to ignore top-level functions.
ignore_top_level_functions: bool,
}
impl Default for MaxStatementsConfig {
fn default() -> Self {
Self { max: DEFAULT_MAX_STATEMENTS, ignore_top_level_functions: false }View on GitHub (pinned to e1e7af627c)
Solutions
- Extract the anonymous body into a named, testable function with fewer statements per unit.
- Raise `max` or set `ignoreTopLevelFunctions: true` in the rule configuration for wiring-style code.
- Simplify the body itself: early returns, table-driven dispatch, and helper extraction reduce raw statement counts.
Example fix
// before
app.get('/report', function (req, res) { /* 13 statements: auth, parse, query, format, ... */ });
// after
app.get('/report', (req, res) => {
reportHandler(req, res).catch(next);
}); Defensive patterns
Strategy: validation
Validate before calling
// Gate anonymous bodies too (same rule/config): oxlint --rule max-statements='{"max":10}' src/
// Route handlers: keep the anonymous wrapper 1-3 statements and delegate. Prevention
- Make callback bodies thin adapters that delegate to named handlers — this also makes the logic unit-testable.
- Avoid IIFEs for module setup; hoisted named functions read better and report with useful names.
- When a middleware grows statements, extract stages (parse, authorize, handle) as separate middleware or helpers.
When it happens
Trigger: Anonymous function expressions and IIFEs with more than 10 direct statements: `router.get('/x', function (req, res) { /* 12 statements */ })`, module-level IIFE setup blocks, callback bodies in event emitters.
Common situations: Route handlers and middleware bodies in Express-style apps; IIFE bootstrap code; converting such anonymous bodies to named functions (message then switches to the named variant); enabling the rule in CI and getting dozens of reports in legacy routes files.
Related errors
- function `{name}` has too many statements ({count}). Maximum
- The {name} has too many lines ({count}). Maximum allowed is
- Function has too many parameters ({}). Maximum allowed is {}
- {name} has a complexity of {complexity}. Maximum allowed is
- Unexpected named {function_name}.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/f7b7c8ea22db3ede.
Report an issue: GitHub.