Implement S8967: inline snapshots should not contain interpolations#7407
Conversation
guillemsarda
left a comment
There was a problem hiding this comment.
No big changes requested
…hared with S8780 into helpers/expect-chain.ts
…the custom-wrapper check
… of once for the whole snapshot
…ts to avoid collision with S5906/expect-chain.ts
…ng the computed-member guard to collectCallChain
… one per interpolation Reduces noise on snapshots with multiple interpolations, per review feedback.
- Replace the isUnresolved-based fallback in isExpectCall with a narrower isGlobalExpect check (no variable, or a variable with no declarations) to avoid misclassifying a shadowed local `expect` (e.g. a function parameter) as the framework global. - Fix collectCallChain's JSDoc: segments are collected furthest from the root call first, not "innermost first".
This comment has been minimized.
This comment has been minimized.
Ruling ReportNew issues flagged (4 issues)S8967vitest/test/browser/fixtures/expect-dom/toMatchScreenshot.test.ts:134 132 | expect(ratio).toMatch(/[01]\.\d{2}/)
133 |
> 134 | expect(errorMessage).toMatchInlineSnapshot(`
135 | expect(element).toMatchScreenshot()
136 | vitest/test/browser/fixtures/expect-dom/toMatchScreenshot.test.ts:182 180 | })
181 |
> 182 | expect(errorMessage).toMatchInlineSnapshot(`
183 | expect(element).toMatchScreenshot()
184 | vitest/test/coverage-test/test/mixed-versions-warning.unit.test.ts:25 23 | const message = warn.mock.calls[0][0]
24 |
> 25 | expect(stripVTControlCharacters(message)).toMatchInlineSnapshot(`
26 | "Loaded vitest@1.0.0 and @vitest/coverage-v8@${version} .
27 | Running mixed versions is not supported and may lead into bugsvitest/test/coverage-test/test/mixed-versions-warning.unit.test.ts:47 45 | const message = warn.mock.calls[0][0]
46 |
> 47 | expect(stripVTControlCharacters(message)).toMatchInlineSnapshot(`
48 | "Loaded vitest@1.0.0 and @vitest/coverage-istanbul@${version} .
49 | Running mixed versions is not supported and may lead into bugs |
The new rule flags 4 genuine toMatchInlineSnapshot() interpolations in the vitest project (screenshot error messages and version warnings).
|
Code Review ✅ Approved 2 resolved / 2 findingsImplements rule S8967 to detect template interpolations in inline snapshots and refactors expectation chain logic into shared helpers. Resolved findings regarding documentation clarity in collectCallChain and Playwright async assertion suppression. ✅ 2 resolved✅ Quality: collectCallChain doc says "innermost first" but returns outermost first
✅ Edge Case: done-callback guard also suppresses Playwright async assertions
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |





Summary
expect(...), includingnot,resolves, andrejectsLinks
Summary by Gitar
S8967to detect template interpolations in Jest and Vitest inline snapshots.expect-call-chain.ts, to supportS8967and refactorS8780.S8780to utilize the newcollectCallChainandgetRootCallhelpers, improving handling of computed member access in expectation chains.S8967and updatedSonar_way_profile.jsonto include the new rule.This will update automatically on new commits.