oxc-project/oxc · warning

File has too many lines ({count}).

Error message

File has too many lines ({count}).

What it means

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.

Source

Thrown at crates/oxc_linter/src/rules/eslint/max_lines.rs:15

use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;
use serde::Deserialize;
use serde_json::Value;

use crate::{
    context::LintContext,
    rule::{DefaultRuleConfig, Rule},
    utils::count_comment_lines,
};

fn max_lines_diagnostic(count: u32, max: u32, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("File has too many lines ({count})."))
        .with_help(format!("Maximum allowed is {max}."))
        .with_label(span)
}

#[derive(Debug, Default, Clone, Deserialize)]
pub struct MaxLines(Box<MaxLinesConfig>);

#[derive(Debug, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct MaxLinesConfig {
    /// Maximum number of lines allowed per file.
    max: u32,
    /// Whether to ignore blank lines when counting.
    skip_blank_lines: bool,
    /// Whether to ignore comments when counting.
    skip_comments: bool,
}

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Split the file by responsibility (extract helpers, components, or constants into sibling modules).
  2. Configure realistic limits and counting rules: `{ "max": 1000, "skipBlankLines": true, "skipComments": true }` for codebases with heavy doc comments.
  3. Exclude generated directories in `.oxlintrc.json` (`ignorePatterns`) so machine-written files are not measured by hand-written-code standards.

Example fix

// before: api-client.js (840 lines: fetch wrappers + types + retry logic + interceptors)

// after:
// api-client/index.js      (re-exports, ~40 lines)
// api-client/endpoints.js  (resource wrappers)
// api-client/retry.js      (retry/backoff helpers)
// api-client/interceptors.js
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json -> "max-lines": ["error", { "max": 400, "skipBlankLines": true, "skipComments": true }]
// plus "ignorePatterns": ["src/generated/**"] for codegen output.

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


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