{"record":{"id":"8974fd6c4c7ab16a","repo":"oxc-project/oxc","slug":"the-name-has-too-many-lines-count-maximum-a","errorCode":null,"errorMessage":"The {name} has too many lines ({count}). Maximum allowed is {max}.","messagePattern":"The (.+?) has too many lines \\((.+?)\\)\\. Maximum allowed is (.+?)\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/max_lines_per_function.rs","lineNumber":26,"sourceCode":"use schemars::JsonSchema;\nuse serde::Deserialize;\nuse serde_json::Value;\n\nuse crate::{\n    AstNode,\n    ast_util::{get_function_name_with_kind, iter_outer_expressions},\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::count_comment_lines,\n};\n\nfn max_lines_per_function_diagnostic(\n    name: &str,\n    count: u32,\n    max: u32,\n    span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"The {name} has too many lines ({count}). Maximum allowed is {max}.\"\n    ))\n    .with_help(\"Consider splitting it into smaller functions.\")\n    .with_label(span)\n}\n\n#[derive(Debug, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct MaxLinesPerFunctionConfig {\n    /// Maximum number of lines allowed in a function.\n    max: u32,\n    /// Skip lines containing just comments.\n    skip_comments: bool,\n    /// Skip lines made up purely of whitespace.\n    skip_blank_lines: bool,\n    /// The `IIFEs` option controls whether IIFEs are included in the line count.\n    /// By default, IIFEs are not considered, but when set to `true`, they will\n    /// be included in the line count for the function.","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/max_lines_per_function.rs#L8-L44","documentation":"Diagnostic from `max-lines-per-function`. It measures the line span of a function (including nested structures but not nested function bodies) and reports it with a human-readable name/kind produced by `get_function_name_with_kind` (e.g. \"FunctionComponent `Button` has too many lines\", \"method `render` has too many lines\"). Default `max` is 50 lines (DEFAULT_MAX_LINES_PER_FUNCTION at crates/oxc_linter/src/rules/eslint/max_lines_per_function.rs:49-54), with `skipBlankLines` and `skipComments` options.","triggerScenarios":"A function whose own body spans more than 50 lines with defaults, e.g. a long lifecycle method, reducer switch, or setup function. Nested functions are measured separately; configuring `{ \"max\": 100, \"skipComments\": true }` shifts the threshold. The diagnostic span covers the offending function.","commonSituations":"React class components and big render methods; Redux reducers with many cases; test setup functions (`beforeEach` bodies) in suites; legacy jQuery-era initialization code; teams enabling the rule after the codebase already contains 100+ line functions and getting flooded.","solutions":["Decompose the function: extract steps into named helpers so each unit stays under the limit (the rule's stated help suggests splitting).","Enable `skipBlankLines`/`skipComments` if formatting and doc comments, not logic, are pushing functions over the line.","Raise `max` for specific realities of the codebase (e.g. generated reducers) or disable the rule for test files via config overrides."],"exampleFix":"// before\nasync function checkout(cart) { /* ~90 lines: validate, price, tax, discount, payment, email */ }\n\n// after\nasync function checkout(cart) {\n  const priced = await priceCart(cart);\n  const paid = await chargePayment(priced);\n  return sendReceiptEmail(paid);\n}","handlingStrategy":"validation","validationCode":"// .oxlintrc.json -> \"max-lines-per-function\": [\"error\", { \"max\": 50, \"skipComments\": true }]\n// CI: oxlint fails the PR before long functions merge.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Extract helpers while adding code to an already-long function — do not let it grow past the limit 'just this once'.","Reducers/handlers with many cases: split per-case handlers or use a lookup map of case -> function.","skipComments/skipBlankLines keep doc-heavy functions honest without penalizing documentation."],"tags":["eslint","oxlint","complexity","function-length","refactor"],"backgroundTag":"function-length-lint","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"}