Skip to content

feat(jest,rstest): add prefer-snapshot-hint rule - #2293

Merged
fansenze merged 4 commits into
mainfrom
feat/prefer-snapshot-hint
Sep 28, 2026
Merged

fansenze merged 4 commits into
mainfrom
feat/prefer-snapshot-hint

Conversation

@elecmonkey

Copy link
Copy Markdown
Member

Motivation

Descriptive hints make external snapshots easier to identify during review, especially when one test produces several snapshots.

Changes

Add rstest/prefer-snapshot-hint and jest/prefer-snapshot-hint.

The default multi mode requires hints in groups containing multiple external snapshot assertions; always requires a hint on every external snapshot assertion. Inline and file snapshots are excluded.

Share hint detection, lexical grouping, options and diagnostics between both plugins, while each adapter retains its framework's call parsing and binding resolution. No fixes are offered because the hint describes what the user intends to capture.

Register the rules without adding them to either recommended preset, because snapshot naming is a style choice.

Credits

Port from eslint-plugin-jest@29.16.6's and @vitest/eslint-plugin@1.6.27's prefer-snapshot-hint.

Intentional differences from upstream

  • Rstest recognizes matchSnapshot and checks every snapshot matcher in a Chai chain. The alias uses the same snapshot implementation as toMatchSnapshot.

  • Rstest accepts interpolated template literals as hints. They always produce strings, and their text becomes part of the snapshot name.

  • Rstest excludes negated snapshots, expect.poll and expect.element chains, and static calls without an assertion factory. These forms do not provide a valid Rstest snapshot assertion.

  • Rstest uses its own binding analysis. This covers test-context assertions, rstack/test, import.meta.rstest and ordinary Rstest assertions exposed by @rstest/playwright.

Related Links

Related #935.

Checklist

  • Tests updated.
  • Documentation updated.

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦀📦 Binary size

Commit d6ec397 merged into base 4812542 — feat(unicorn): add consistent-template-literal-escape rule (#2315).

Binary Base This PR Change
rslint (linux-x64-gnu) 39.40 MiB 39.42 MiB +24.00 KiB (+0.06%)

Stripped go build -ldflags="-s -w" ./cmd/rslint, Go 1.27.0, linux/amd64 · run · 2026-09-28 06:40 UTC

@elecmonkey
elecmonkey marked this pull request as ready for review September 24, 2026 13:19
@elecmonkey
elecmonkey force-pushed the feat/prefer-snapshot-hint branch from 91cd019 to 6f82f58 Compare September 24, 2026 16:26

@fansenze fansenze left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found two reproducible false positives in jest/prefer-snapshot-hint. The existing tests for 14 affected Go packages pass; the additional examples below reproduce the issues on this commit. The equivalent Rstest cases pass.

Comment thread internal/plugins/jest/rules/prefer_snapshot_hint/prefer_snapshot_hint.go Outdated
Comment thread internal/plugins/jest/utils/call_analysis.go
@fansenze

Copy link
Copy Markdown
Contributor

@elecmonkey Could you please resolve the merge conflicts?

@elecmonkey
elecmonkey force-pushed the feat/prefer-snapshot-hint branch from a8156a6 to d6ec397 Compare September 28, 2026 06:34
@fansenze
fansenze merged commit 706caa7 into main Sep 28, 2026
15 checks passed
@fansenze
fansenze deleted the feat/prefer-snapshot-hint branch September 28, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants