oxc-project/oxc · warning · OxcDiagnostic

Snapshot is too long.

Error message

Snapshot is too long.

What it means

The `no_snapshot` variant of oxlint rule `jest/no-large-snapshots` (shared with vitest), defined at crates/oxc_linter/src/rules/shared/jest_vitest/no_large_snapshots.rs:19. It fires when the effective size limit is zero, i.e. the configuration bans snapshots outright: the help reads 'Expected to not encounter a Jest or Vitest snapshot but one was found that is N lines long'. For inline snapshots this is controlled by maxSize/inlineMaxSize set to 0.

Source

Thrown at crates/oxc_linter/src/rules/shared/jest_vitest/no_large_snapshots.rs:20

use oxc_ast::{
    AstKind,
    ast::{Expression, ExpressionStatement, MemberExpression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_span::{GetSpan, Span};
use oxc_str::CompactStr;
use rustc_hash::FxHashMap;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::{
    context::LintContext,
    rule::DefaultRuleConfig,
    utils::{PossibleJestNode, iter_possible_jest_call_node, parse_expect_jest_fn_call},
};

fn no_snapshot(line_count: u32, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Snapshot is too long.")
        .with_help(format!(
            "Expected to not encounter a Jest or Vitest snapshot but one was found that is {line_count} lines long"
        ))
        .with_label(span)
}

fn too_long_snapshot(line_limit: u32, line_count: u32, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Snapshot is too long.")
        .with_help(format!(
            "Expected Jest or Vitest snapshot to be no longer than {line_limit} lines but it was {line_count} lines long"
        ))
        .with_label(span)
}

pub const DOCUMENTATION: &str = r"### What it does

Disallow large snapshots.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Convert the inline snapshot into explicit assertions (toBe / toMatchObject) since the project policy bans snapshots
  2. If small inline snapshots are acceptable, raise the limit: { "jest/no-large-snapshots": ["error", { "maxSize": 0, "inlineMaxSize": 6 }] }
  3. Whitelist specific snapshots via the allowedSnapshots map (snapshot-file path to regex/exact names) instead of removing the ban

Example fix

// before (inlineMaxSize: 0)
expect(render()).toMatchInlineSnapshot(`
  <button>Buy</button>
`);

// after
expect(render()).toContain('Buy');
Defensive patterns

Strategy: validation

Validate before calling

rg -n "toMatchInlineSnapshot\(" tests/ # any inline snapshot trips a zero maxSize policy

Prevention

When it happens

Trigger: From report_in_span (no_large_snapshots.rs:263-278): an expect(...).toMatchInlineSnapshot(...) / toThrowErrorMatchingInlineSnapshot(...) argument spans more lines than the effective inline limit and inline_max_size() == 0, meaning any inline snapshot at all is disallowed. In .snap files the equivalent branch reports when a stored snapshot is found while max_size is 0.

Common situations: Teams that have decided to ban inline snapshots entirely and set maxSize: 0; config copied from another repo with a zero limit; enabling the rule with a deliberate zero policy and then encountering generated snapshots during a migration.

Related errors


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