New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new Style/ClassEqualityComparison
cop
#8833
Add new Style/ClassEqualityComparison
cop
#8833
Conversation
Yeah, I agree it's a style cop. Might be a good idea to mention this in the style guide as well. |
| - | ||
|=== | ||
|
||
This cop enforces the use of `Object#instance_of?` instead of class comparison |
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.
Btw, you can use kind_of?
as well. I think we have some other cop for this, so that one should honor the config of the existing cop.
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.
kind_of?
is an alias for is_a?
, which checks also superclasses. So this should be instance_of?
for sure.
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.
I keep mixing those up. :-)
You'll also need to rebase. |
665cf42
to
78305af
Compare
Rebased and added a link to style guide. |
Thanks! |
…yComparison` Fixes rubocop#11914. This PR fixes an incorrect examples for `Style/ClassEqualityComparison`. The original `IgnoredMethods` (later renamed `AllowedMethods`) was introduced by rubocop#8833. OTOH, rubocop#10809 seems to have mis-documented rubocop#8833.
This cop enforces the use of
Object#instance_of?
instead of class comparison for equality.Ran it on 30k files and got 130 offenses. So seems useful.
Not sure if this should be in
Style
orLint
(looks likeStyle
for me).