Skip to content

Commit

Permalink
[Fix #9380] Mark Style/FloatDivision as unsafe
Browse files Browse the repository at this point in the history
Fixes #9380.

This PR marks `Style/FloatDivision` as unsafe.

If operand variable is a string object then `.to_f` will be removed
and an error will occur.
  • Loading branch information
koic authored and bbatsov committed Jan 15, 2021
1 parent b72ae11 commit d939849
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/change_mark_unsafe_for_style_float_division.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#9380](https://github.com/rubocop-hq/rubocop/issues/9380): Mark `Style/FloatDivision` as unsafe. ([@koic][])
1 change: 1 addition & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3307,6 +3307,7 @@ Style/FloatDivision:
Enabled: true
VersionAdded: '0.72'
VersionChanged: '1.6'
Safe: false
EnforcedStyle: single_coerce
SupportedStyles:
- left_coerce
Expand Down
3 changes: 3 additions & 0 deletions lib/rubocop/cop/style/float_division.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module Style
# It is recommended to either always use `fdiv` or coerce one side only.
# This cop also provides other options for code consistency.
#
# This cop is marked as unsafe, because if operand variable is a string object
# then `.to_f` will be removed and an error will occur.
#
# @example EnforcedStyle: single_coerce (default)
# # bad
# a.to_f / b.to_f
Expand Down

0 comments on commit d939849

Please sign in to comment.