{"record":{"id":"ddf24be32a9927bc","repo":"oxc-project/oxc","slug":"file-has-too-many-lines-count","errorCode":null,"errorMessage":"File has too many lines ({count}).","messagePattern":"File has too many lines \\((.+?)\\)\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/max_lines.rs","lineNumber":15,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\nuse serde_json::Value;\n\nuse crate::{\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::count_comment_lines,\n};\n\nfn max_lines_diagnostic(count: u32, max: u32, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"File has too many lines ({count}).\"))\n        .with_help(format!(\"Maximum allowed is {max}.\"))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct MaxLines(Box<MaxLinesConfig>);\n\n#[derive(Debug, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct MaxLinesConfig {\n    /// Maximum number of lines allowed per file.\n    max: u32,\n    /// Whether to ignore blank lines when counting.\n    skip_blank_lines: bool,\n    /// Whether to ignore comments when counting.\n    skip_comments: bool,\n}\n","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/max_lines.rs#L1-L33","documentation":"Reported by the `max-lines` rule when a source file's total line count exceeds the configured maximum; oxc defaults to `max: 300` with `skipBlankLines: false` and `skipComments: false` (crates/oxc_linter/src/rules/eslint/max_lines.rs:42-45). The count is based on the file's span/source text, and the help text states the allowed maximum. It is a file-size hygiene rule.","triggerScenarios":"Any file longer than 300 lines with default config triggers on the file's span. `{ \"max-lines\": [\"error\", { \"max\": 500, \"skipBlankLines\": true, \"skipComments\": true }] }` changes both the threshold and what counts. Because it is file-level, the diagnostic appears once per over-limit file.","commonSituations":"Generated files (GraphQL codegen, protobuf stubs, openapi clients) checked into src and covered by lint; accumulated utils or test files growing past 300 lines; enabling the rule repo-wide and facing hundreds of pre-existing violations; teams disagreeing whether blank/comment lines should count (skipBlankLines/skipComments).","solutions":["Split the file by responsibility (extract helpers, components, or constants into sibling modules).","Configure realistic limits and counting rules: `{ \"max\": 1000, \"skipBlankLines\": true, \"skipComments\": true }` for codebases with heavy doc comments.","Exclude generated directories in `.oxlintrc.json` (`ignorePatterns`) so machine-written files are not measured by hand-written-code standards."],"exampleFix":"// before: api-client.js (840 lines: fetch wrappers + types + retry logic + interceptors)\n\n// after:\n// api-client/index.js      (re-exports, ~40 lines)\n// api-client/endpoints.js  (resource wrappers)\n// api-client/retry.js      (retry/backoff helpers)\n// api-client/interceptors.js","handlingStrategy":"validation","validationCode":"// .oxlintrc.json -> \"max-lines\": [\"error\", { \"max\": 400, \"skipBlankLines\": true, \"skipComments\": true }]\n// plus \"ignorePatterns\": [\"src/generated/**\"] for codegen output.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Split modules by responsibility during normal editing — the 300-line default then rarely triggers.","Keep generated code out of linted paths (ignorePatterns) or behind a generation boundary from day one.","When a file approaches the limit during a PR, split it in the same PR; deferring creates the 2000-line file nobody wants to touch."],"tags":["eslint","oxlint","style","file-size","maintainability"],"backgroundTag":"file-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"}