{"record":{"id":"6830523ca825421e","repo":"oxc-project/oxc","slug":"function-name-has-too-many-statements-count","errorCode":null,"errorMessage":"function `{name}` has too many statements ({count}). Maximum allowed is {max}.","messagePattern":"function `(.+?)` has too many statements \\((.+?)\\)\\. Maximum allowed is (.+?)\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/max_statements.rs","lineNumber":31,"sourceCode":"use schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\nuse serde_json::Value;\n\nuse crate::{context::LintContext, rule::Rule};\n\nfn max_statements_diagnostic(\n    name: Option<&str>,\n    count: u32,\n    max: u32,\n    span: Span,\n) -> OxcDiagnostic {\n    let message = if let Some(name) = name {\n        format!(\"function `{name}` has too many statements ({count}). Maximum allowed is {max}.\")\n    } else {\n        format!(\"function has too many statements ({count}). Maximum allowed is {max}.\")\n    };\n\n    OxcDiagnostic::warn(message)\n        .with_help(\"Consider splitting it into smaller functions.\")\n        .with_label(span)\n}\n\nconst DEFAULT_MAX_STATEMENTS: u32 = 10;\n\n#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct MaxStatementsConfig {\n    /// Maximum number of statements allowed per function.\n    max: u32,\n    /// Whether to ignore top-level functions.\n    ignore_top_level_functions: bool,\n}\n\nimpl Default for MaxStatementsConfig {\n    fn default() -> Self {\n        Self { max: DEFAULT_MAX_STATEMENTS, ignore_top_level_functions: false }","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/max_statements.rs#L13-L49","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["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').","Raise `max` in config to a team-realistic value (e.g. 25) or enable `ignoreTopLevelFunctions: true` when long top-level wiring is acceptable.","Move sequential steps into a data-driven loop/table (strategy map) so many statements collapse into one."],"exampleFix":"// before\nfunction initApp(config) { /* 14 statements: read env, connect db, seed, routes, listen, ... */ }\n\n// after\nfunction initApp(config) {\n  const db = await connectDatabase(config);\n  registerRoutes(app, db);\n  startServer(config.port);\n}","handlingStrategy":"validation","validationCode":"// CI: oxlint --rule max-issues... -> use max-statements: [\"error\", 10]\n// Enable ignoreTopLevelFunctions for bootstrap files: {\"max\": 10, \"ignoreTopLevelFunctions\": true}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Split by phase while writing: parse, validate, execute as separate named helpers keeps every unit under budget.","ignoreTopLevelFunctions:true separates module wiring (acceptable to be long) from logic functions (should be short).","Statement counts are a proxy — a function that needs more than ~10 statements usually owns more than one responsibility."],"tags":["eslint","oxlint","complexity","function-length","statements"],"backgroundTag":"too-many-statements","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}