-
-
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
Add new cop Style/FloatDivision
#7153
Conversation
2e9cf2e
to
c7ba4b0
Compare
c7ba4b0
to
a1712bc
Compare
a1712bc
to
1c48371
Compare
After some deliberation I agree with @koic that the best default would be something that just warns if you use |
See also https://blog.rubystyle.guide/ruby/2019/06/21/float-division.html - unfortunately we got no feedback on it. |
This PR updates a style guide for "Float Division". The original issue for which this style was proposed. rubocop#628 It is an update based on the following argument. rubocop/rubocop#7153 (comment) The following is a quote from the argument about the reason for this change. > I wanted to show the following option to make a bad case only when both have `to_f`. > > ```ruby > # bad > a.to_f / b.to_f > > # good > a.to_f / b > a / b.to_f > a.fdiv(b) > ``` > > Whether `to_f` is used on the left or right depends on the nature of `a` > or `b` parameter. On the other hand, it is redundant that `to_f` is used > in both. At that time, I think it is better to let users choose whether > to remove the left side `to_f` or the right side `to_f`. This is the > reason I recommend this option to default.
Thanks for your consideration. I opened a PR rubocop/ruby-style-guide#767 to rubocop-hq/ruby-style-guide repo. |
This PR updates a style guide for "Float Division". The original issue for which this style was proposed. #628 It is an update based on the following argument. rubocop/rubocop#7153 (comment) The following is a quote from the argument about the reason for this change. > I wanted to show the following option to make a bad case only when both have `to_f`. > > ```ruby > # bad > a.to_f / b.to_f > > # good > a.to_f / b > a / b.to_f > a.fdiv(b) > ``` > > Whether `to_f` is used on the left or right depends on the nature of `a` > or `b` parameter. On the other hand, it is redundant that `to_f` is used > in both. At that time, I think it is better to let users choose whether > to remove the left side `to_f` or the right side `to_f`. This is the > reason I recommend this option to default.
1c48371
to
6f2dc54
Compare
@koic PR updated. Changed default style to |
6f2dc54
to
c5708ae
Compare
c5708ae
to
8165649
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 looks good to me. Thank you for the many updates!
StyleGuide: https://rubystyle.guide/#float-division
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.