-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
chore: add prefer-to-contain rule #174
chore: add prefer-to-contain rule #174
Conversation
`expect(a.includes(b)).toEqual("test")`, | ||
`expect(a.includes(b)).toBe("test")`, | ||
`expect(a.includes()).toEqual()`, | ||
`expect(a.includes(b)).toBe(false)`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we support this, and suggest expect(a).not.toContain(b)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree on supporting the .not.toContain()
syntax. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added not.toContain
suggestion
8227f3e
to
14bb2a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Left a couple of inline comments, but this is looking really good 🙂
docs/rules/prefer-to-contain.md
Outdated
``` | ||
|
||
```js | ||
expect(a).toContain(b); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing not
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
rules/prefer-to-contain.js
Outdated
node.arguments[0].arguments.length === 1 && | ||
node.arguments[0].arguments[0] | ||
) { | ||
const sourceCode = context.getSourceCode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we move all these variables into the the fix
closure to avoid the hit of calculating them unless people call fix
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved
create(context) { | ||
return { | ||
CallExpression(node) { | ||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this if
is really verbose, could you clean it up? Not a bigge (we can do it later), but 15 lines seems excessive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broke it in multiple methods
rules/prefer-to-contain.js
Outdated
CallExpression(node) { | ||
if ( | ||
!( | ||
expectNotCase(node) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about e.g. expect(a.includes(b)).not.toEqual(true);
? might be weird enough that we don't need to support it, I guess 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'a a little weird but it's a nice to have. Added it to the rule!
8335e71
to
254bca7
Compare
rules/prefer-to-contain.js
Outdated
return getNegationFixes(node, sourceCode, fixer).concat(fixArr); | ||
} | ||
|
||
const equalityArgument = isEqualityNegation(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI is complaining that this line is not covered by tests. Mind adding a test for the other case (or removing the ternary)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was not used so removed it, the coverage is fine now.
254bca7
to
9358170
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thank you so much for sticking with us!
🎉 This PR is included in version 21.25.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
fixes #100