oxc-project/oxc · warning · OxcDiagnostic

function `{name}` has too many statements ({count}). Maximum

Error message

function `{name}` has too many statements ({count}). Maximum allowed is {max}.

What it means

The named variant of the `max-statements` diagnostic. The rule counts statements in a function body (default `max: 10`, `DEFAULT_MAX_STATEMENTS` at crates/oxc_linter/src/rules/eslint/max_statements.rs:32) and reports when exceeded; when the function has an inferable name the message includes it as ``function `name` has too many statements (...)``. Options include `ignoreTopLevelFunctions` to skip module-level functions (crates/oxc_linter/src/rules/eslint/max_statements.rs:35-38).

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

  1. Split the function into smaller named units, each doing one phase of the work (the diagnostic's help text says 'Consider splitting it into smaller functions').
  2. Raise `max` in config to a team-realistic value (e.g. 25) or enable `ignoreTopLevelFunctions: true` when long top-level wiring is acceptable.
  3. Move sequential steps into a data-driven loop/table (strategy map) so many statements collapse into one.

Example fix

// before
function initApp(config) { /* 14 statements: read env, connect db, seed, routes, listen, ... */ }

// after
function initApp(config) {
  const db = await connectDatabase(config);
  registerRoutes(app, db);
  startServer(config.port);
}
Defensive patterns

Strategy: validation

Validate before calling

// CI: oxlint --rule max-issues... -> use max-statements: ["error", 10]
// Enable ignoreTopLevelFunctions for bootstrap files: {"max": 10, "ignoreTopLevelFunctions": true}

Prevention

When it happens

Trigger: A named function or method whose direct body contains more than `max` statements: a long reducer case, a setup routine, aSaga handler. Each statement (declarations, expressions, if, loops) counts; nested function bodies count toward their own function's total, not the outer one.

Common situations: Utility/bootstrap functions that accrete setup steps; procedural migration scripts; enabling the rule (it is in pedantic-style sets) on an existing codebase where 20-50 statement functions are common; test helper builders.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/6830523ca825421e. Report an issue: GitHub.