{"record":{"id":"17e19bd5423419d4","repo":"oxc-project/oxc","slug":"tomatchsnapshot-takes-at-most-two-arguments","errorCode":null,"errorMessage":"`toMatchSnapshot` takes at most two arguments.","messagePattern":"`toMatchSnapshot` takes at most two arguments\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/prefer_snapshot_hint.rs","lineNumber":22,"sourceCode":"\nuse oxc_ast::{\n    AstKind,\n    ast::{CallExpression, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_semantic::NodeId;\nuse oxc_span::Span;\n\nuse crate::{\n    context::LintContext,\n    utils::{\n        JestFnKind, JestGeneralFnKind, PossibleJestNode, collect_possible_jest_call_node,\n        parse_expect_jest_fn_call,\n    },\n};\n\nfn snapshot_matcher_too_many_arguments_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"`toMatchSnapshot` takes at most two arguments.\")\n        .with_help(\"Pass a hint string, or a property matcher object followed by a hint string.\")\n        .with_label(span)\n}\n\nfn snapshot_missing_hint_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Snapshot is missing a hint.\")\n        .with_help(\"Include a hint string to identify this snapshot in the snapshot file.\")\n        .with_label(span)\n}\n\nfn snapshot_hint_must_be_string_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Snapshot hint must be a string literal.\")\n        .with_help(\n            \"Provide a string literal as the hint, or pass a property matcher object as the first argument and the hint string as the second.\",\n        )\n        .with_label(span)\n}\n","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/prefer_snapshot_hint.rs#L4-L40","documentation":"This is the oxlint `prefer-snapshot-hint` rule (jest/vitest plugin), argument-count branch. `toMatchSnapshot()` accepts at most two arguments — a hint string, or a property-matcher object followed by a hint string. Passing three or more is always a bug (extra args are ignored), so the linter rejects it outright before even considering the hint policy.","triggerScenarios":"A `toMatchSnapshot` matcher call (recognized via `parse_expect_jest_fn_call` member scan) with `arguments.len() > 2`, in a scope that the mode (`multi`) requires hints for — e.g. `expect(x).toMatchSnapshot({}, 'hint', 'extra')`.","commonSituations":"Chaining legacy calls that accumulated arguments over time; misunderstanding the property-matcher + hint signature; refactoring from inline snapshots that carried extra flags.","solutions":["Reduce to the two valid forms: `toMatchSnapshot('my hint')` or `toMatchSnapshot(propertyMatchers, 'my hint')`.","Delete leftover arguments that were meaningful in another matcher but not here."],"exampleFix":"// before\nexpect(user).toMatchSnapshot({ createdAt: expect.any(Date) }, 'saved user', true);\n\n// after\nexpect(user).toMatchSnapshot({ createdAt: expect.any(Date) }, 'saved user');","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{ \"rules\": { \"jest/prefer-snapshot-hint\": \"error\" } }\n\nnpx oxlint tests/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Learn the two-argument ceiling: hint, or (propertyMatchers, hint) — nothing else.","Delete stale arguments when converting matchers instead of carrying them over."],"tags":["jest","vitest","oxlint","testing","snapshots","api-misuse","static-analysis"],"backgroundTag":"snapshot-hint","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"}