feat(jest,rstest): add prefer-snapshot-hint rule - #2293
Merged
Merged
Conversation
Contributor
🦀📦 Binary sizeCommit
Stripped |
elecmonkey
marked this pull request as ready for review
September 24, 2026 13:19
elecmonkey
force-pushed
the
feat/prefer-snapshot-hint
branch
from
September 24, 2026 16:26
91cd019 to
6f82f58
Compare
fansenze
reviewed
Sep 25, 2026
fansenze
left a comment
Contributor
There was a problem hiding this comment.
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.
Contributor
|
@elecmonkey Could you please resolve the merge conflicts? |
elecmonkey
force-pushed
the
feat/prefer-snapshot-hint
branch
from
September 28, 2026 06:34
a8156a6 to
d6ec397
Compare
fansenze
approved these changes
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Descriptive hints make external snapshots easier to identify during review, especially when one test produces several snapshots.
Changes
Add
rstest/prefer-snapshot-hintandjest/prefer-snapshot-hint.The default
multimode requires hints in groups containing multiple external snapshot assertions;alwaysrequires 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
recommendedpreset, because snapshot naming is a style choice.Credits
Port from
eslint-plugin-jest@29.16.6's and@vitest/eslint-plugin@1.6.27'sprefer-snapshot-hint.Intentional differences from upstream
Rstest recognizes
matchSnapshotand checks every snapshot matcher in a Chai chain. The alias uses the same snapshot implementation astoMatchSnapshot.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.pollandexpect.elementchains, 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.rstestand ordinary Rstest assertions exposed by@rstest/playwright.Related Links
Related #935.
Checklist