Skip to content
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

InverseMethods false positive for Module#<,>,>=,<= #5619

Closed
printercu opened this issue Mar 2, 2018 · 3 comments · Fixed by #5638
Closed

InverseMethods false positive for Module#<,>,>=,<= #5619

printercu opened this issue Mar 2, 2018 · 3 comments · Fixed by #5638

Comments

@printercu
Copy link

Hi!

I've just faced an offence with code: !(klass < BaseClass) which checks that class from variable is not a subclass of BaseClass. Here is the message:

RuboCop: Style/InverseMethods: Use `>` instead of inverting `<=`

I've checked issues but have not found related. I think there is no way to make this cop handle correctly Number#< and Module#<. WDYT?

PS. in this particular case it was ok for me to switch to <=>, because it's guaranteed that klass can not be superclass of BaseClass.

@mikegee
Copy link
Contributor

mikegee commented Mar 2, 2018

Style/InverseMethods could be changed to suppress offenses when one of the operands looks like a class or module (capital first letter, but not all-caps).

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 12, 2018

I keep learning new things about Ruby after all those years - I was always using the ancestors method. 😄

@Drenmi
Copy link
Collaborator

Drenmi commented Mar 12, 2018

Matz:

You shouldn't really be doing type checks in Ruby.

Also Matz:

Let's add some zany facilities for advanced type checking.

😅

rrosenblum added a commit to rrosenblum/rubocop that referenced this issue Mar 12, 2018
bbatsov pushed a commit that referenced this issue Mar 13, 2018
This was referenced Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants