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

Don't consider <=> a comparison method #4615

Merged
merged 1 commit into from Aug 24, 2017

Conversation

iGEL
Copy link
Contributor

@iGEL iGEL commented Jul 19, 2017

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 #4603 by me, where I just prevented Style/YodaCondition to consider it.

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Used the same coding conventions as the rest of the project.
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • All tests(rake spec) are passing.
  • The new code doesn't generate RuboCop offenses that are checked by rake internal_investigation.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Updated cop documentation with rake generate_cops_documentation (required only when you've added a new cop or changed the configuration/documentation of an existing cop).

@iGEL iGEL force-pushed the dont_compare_spaceships branch 2 times, most recently from 80ce153 to b771c08 Compare July 19, 2017 07:22
@@ -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 }
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -22,7 +22,7 @@ class Node < Parser::AST::Node # rubocop:disable Metrics/ClassLength
include RuboCop::AST::Sexp
extend NodePattern::Macros

COMPARISON_OPERATORS = %i[== === != <= >= > < <=>].freeze
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 8, 2017

You'll have to rebase on top of the current master and address the failing build.

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 24, 2017

@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.
@iGEL
Copy link
Contributor Author

iGEL commented Aug 24, 2017

@bbatsov Pong :-)

@bbatsov bbatsov merged commit e900036 into rubocop:master Aug 24, 2017
@bbatsov
Copy link
Collaborator

bbatsov commented Aug 24, 2017

👍

iGEL added a commit to iGEL/rubocop that referenced this pull request Oct 22, 2017
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.
@iGEL iGEL mentioned this pull request Oct 22, 2017
11 tasks
bbatsov pushed a commit that referenced this pull request Oct 22, 2017
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants