{"record":{"id":"aa875339028ff026","repo":"oxc-project/oxc","slug":"snapshot-is-too-long","errorCode":null,"errorMessage":"Snapshot is too long.","messagePattern":"Snapshot is too long\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/no_large_snapshots.rs","lineNumber":20,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Expression, ExpressionStatement, MemberExpression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_span::{GetSpan, Span};\nuse oxc_str::CompactStr;\nuse rustc_hash::FxHashMap;\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse crate::{\n    context::LintContext,\n    rule::DefaultRuleConfig,\n    utils::{PossibleJestNode, iter_possible_jest_call_node, parse_expect_jest_fn_call},\n};\n\nfn no_snapshot(line_count: u32, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Snapshot is too long.\")\n        .with_help(format!(\n            \"Expected to not encounter a Jest or Vitest snapshot but one was found that is {line_count} lines long\"\n        ))\n        .with_label(span)\n}\n\nfn too_long_snapshot(line_limit: u32, line_count: u32, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Snapshot is too long.\")\n        .with_help(format!(\n            \"Expected Jest or Vitest snapshot to be no longer than {line_limit} lines but it was {line_count} lines long\"\n        ))\n        .with_label(span)\n}\n\npub const DOCUMENTATION: &str = r\"### What it does\n\nDisallow large snapshots.\n","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/no_large_snapshots.rs#L2-L38","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Convert the inline snapshot into explicit assertions (toBe / toMatchObject) since the project policy bans snapshots","If small inline snapshots are acceptable, raise the limit: { \"jest/no-large-snapshots\": [\"error\", { \"maxSize\": 0, \"inlineMaxSize\": 6 }] }","Whitelist specific snapshots via the allowedSnapshots map (snapshot-file path to regex/exact names) instead of removing the ban"],"exampleFix":"// before (inlineMaxSize: 0)\nexpect(render()).toMatchInlineSnapshot(`\n  <button>Buy</button>\n`);\n\n// after\nexpect(render()).toContain('Buy');","handlingStrategy":"validation","validationCode":"rg -n \"toMatchInlineSnapshot\\(\" tests/ # any inline snapshot trips a zero maxSize policy","typeGuard":null,"tryCatchPattern":null,"preventionTips":["If policy bans snapshots, codify it with maxSize 0 and review PRs for new matchers","Prefer explicit assertions for small objects so the ban costs little","Document the zero-limit policy in the repo lint config comments"],"tags":["jest","vitest","oxlint","testing","snapshots","config"],"backgroundTag":"oversized-snapshot","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}