feat: create prefer-comparison-matcher
rule
#1015
Merged
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.
As documented, I decided to ignore the fact that you can use the comparison operators with strings but not with the jest matchers because I really don't think there's a good & common-enough use case for doing that (maybe aside from checking string sorting?) that makes it worth giving up being able to autofix.
Am open to PRs if someone wanted to have an option like
assumeVariablesHoldNumbers
that can be set tofalse
to make this rule give suggestions instead of autofix, but for now have left that out.I've also made this not do anything with the equality operators, as I'm making that into its own rule since that will have to use suggestions and is a little more complicated in terms of there being three possible operators.
Finally, this rule doesn't enforce one specific matcher in regards to
not
e.g. it doesn't warn that.not.toBeLessThan
could be replaced with.toBeGreaterThanOrEqual
.Closes #989