feat(eslint-plugin-jest): add prefer-equality-matcher rule#1061
Open
eryue0220 wants to merge 4 commits into
Open
feat(eslint-plugin-jest): add prefer-equality-matcher rule#1061eryue0220 wants to merge 4 commits into
prefer-equality-matcher rule#1061eryue0220 wants to merge 4 commits into
Conversation
fansenze
reviewed
Jun 8, 2026
| return | ||
| } | ||
|
|
||
| left, right, negated, ok := parseStrictEqualityComparison(expectArgs[0]) |
Contributor
There was a problem hiding this comment.
False negatives: a parenthesized comparison is asserted valid, but real eslint-plugin-jest@29 reports it.
expect((a === b)).toBe(true) → expect((a)).toBe(b) col 19
expect((a !== b)).toBe(true) → expect((a)).not.toBe(b) col 19
tsgo keeps ParenthesizedExpression while the upstream parser elides it, so the Kind != BinaryExpression check bails out. Unwrap before parsing — parens only, so expect((a === b) as boolean)... stays valid:
left, right, negated, ok := parseStrictEqualityComparison(ast.SkipParentheses(expectArgs[0]))Then move both cases to invalid.
| return | ||
| } | ||
|
|
||
| matcherValue, ok := isBooleanLiteral(matcherArgs[0]) |
Contributor
There was a problem hiding this comment.
False negatives: a parenthesized / type-asserted matcher arg is asserted valid, but real eslint-plugin-jest@29 reports it.
expect(a === b).toBe((true)) → expect(a).toBe((b)) col 17
expect(a === b).toBe(true as boolean) → expect(a).toBe(b as boolean) col 17
Upstream's getFirstMatcherArg runs followTypeAssertionChain (parens + as/<T>), but isBooleanLiteral here gets the raw node. Reuse the existing util:
matcherValue, ok := isBooleanLiteral(utils.UnwrapBasicTypeAssertions(matcherArgs[0]))Then move both cases to invalid.
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.
Summary
Port
prefer-equality-matcherfrom eslint-plugin-jest to rslintRelated Links
Tracking issue: #476
eslint-plugin-jest/prefer-equality-matcher doc code
Checklist