feat(eslint-plugin-jest): add prefer-strict-equal rule#623
feat(eslint-plugin-jest): add prefer-strict-equal rule#623eryue0220 wants to merge 5 commits intoweb-infra-dev:mainfrom
prefer-strict-equal rule#623Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new Jest linting rule, prefer-strict-equal, which promotes the use of toStrictEqual() over toEqual() in expect() calls. The review identifies a bug where the rule incorrectly flags expect().not.toEqual() and provides a code suggestion to fix this by checking for the .not modifier. Additionally, it suggests adding test cases for this not modifier scenario in both the Go and TypeScript test suites to ensure correct behavior. The review also recommends enhancing the rule's documentation to provide a more detailed explanation of why toStrictEqual() is preferred, specifically regarding its handling of undefined properties.
internal/plugins/jest/rules/prefer_strict_equal/prefer_strict_equal_test.go
Show resolved
Hide resolved
packages/rslint-test-tools/tests/eslint-plugin-jest/rules/prefer-strict-equal.test.ts
Show resolved
Hide resolved
internal/plugins/jest/rules/prefer_strict_equal/prefer_strict_equal.md
Outdated
Show resolved
Hide resolved
internal/plugins/jest/rules/prefer_strict_equal/prefer_strict_equal.go
Outdated
Show resolved
Hide resolved
…equal.md Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
| if kind != ast.KindIdentifier && kind != ast.KindStringLiteral { | ||
| continue | ||
| } |
There was a problem hiding this comment.
getElementAccessName in jest.go also supports ast.KindNoSubstitutionTemplateLiteral, which means expect(x)[toEqual](y) will produce a MemberEntry with Name: "toEqual" and Node.Kind: NoSubstitutionTemplateLiteral. This filter skips it silently, so the rule won't report on template-literal bracket access.
if kind != ast.KindIdentifier && kind != ast.KindStringLiteral && kind != ast.
KindNoSubstitutionTemplateLiteral {
continue
}
Summary
Port
prefer-strict-equalfrom eslint-plugin-jest to rslint.Related Links
Tracking issue: #476
eslint-plugin-jest/prefer-strict-equal doc code
Checklist