Skip to content

feat(eslint-plugin-jest): add prefer-equality-matcher rule#1061

Open
eryue0220 wants to merge 4 commits into
web-infra-dev:mainfrom
eryue0220:feat/jest-prefer-equality-matcher
Open

feat(eslint-plugin-jest): add prefer-equality-matcher rule#1061
eryue0220 wants to merge 4 commits into
web-infra-dev:mainfrom
eryue0220:feat/jest-prefer-equality-matcher

Conversation

@eryue0220
Copy link
Copy Markdown
Contributor

Summary

Port prefer-equality-matcher from eslint-plugin-jest to rslint

Related Links

Tracking issue: #476
eslint-plugin-jest/prefer-equality-matcher doc code

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

return
}

left, right, negated, ok := parseStrictEqualityComparison(expectArgs[0])
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.

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])
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.

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.

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