-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Don't consider <=> a comparison method #4615
Conversation
80ce153
to
b771c08
Compare
b771c08
to
53d2fa5
Compare
@@ -412,7 +412,7 @@ | |||
context 'with a comparison method' do | |||
let(:source) { 'foo.bar <=> :baz' } | |||
|
|||
it { expect(send_node.comparison_method?).to be_truthy } | |||
it { expect(send_node.comparison_method?).to be_falsey } |
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.
Maybe change the source
here instead of the expectation?
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.
Good point, that was stupid. Fixed.
53d2fa5
to
27d4d38
Compare
27d4d38
to
e014dfb
Compare
@@ -22,7 +22,7 @@ class Node < Parser::AST::Node # rubocop:disable Metrics/ClassLength | |||
include RuboCop::AST::Sexp | |||
extend NodePattern::Macros | |||
|
|||
COMPARISON_OPERATORS = %i[== === != <= >= > < <=>].freeze |
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'd add a note here about why <=>
is not considered a comparison method.
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.
✔️
You'll have to rebase on top of the current master and address the failing build. |
@iGEL ping :-) |
I believe, the `<=>` operator should not be considered as a `.comparison_method?`. The main reason is, that this method in difference to all other comparison methods doesn't return a boolean, but `-1`, `0` or `1`. Thus, many assumptions for comparison methods don't apply, for example, there isn't an inverse comparison method (like `<` is the inverse of `>=)`, `* -1` isn't a comparison). This is an alternative to rubocop#4603 by me.
e014dfb
to
5390f4e
Compare
@bbatsov Pong :-) |
👍 |
In @e900036, I changed a spec to make it pass without thinking about it. This was pointed out in the [code review](rubocop#4615 (review)) by @mikegee and I fixed it, but then somehow that thing got lost again, possibly during rebasing. Sorry about that.
In @e900036, I changed a spec to make it pass without thinking about it. This was pointed out in the [code review](#4615 (review)) by @mikegee and I fixed it, but then somehow that thing got lost again, possibly during rebasing. Sorry about that.
I believe, the
<=>
operator should not be considered as a.comparison_method?
.The main reason is, that this method in difference to all other comparison methods doesn't return a boolean, but
-1
,0
or1
. Thus, many assumptions for comparison methods don't apply, for example,there isn't an inverse comparison method (like
<
is the inverse of>=)
,* -1
isn't a comparison).This is an alternative to #4603 by me, where I just prevented
Style/YodaCondition
to consider it.[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).rake spec
) are passing.rake internal_investigation
.and description in grammatically correct, complete sentences.
rake generate_cops_documentation
(required only when you've added a new cop or changed the configuration/documentation of an existing cop).