Skip to content

Commit

Permalink
Tweak offense message for Lint/NumberConversion
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed Mar 29, 2021
1 parent 43b26a6 commit 464c4df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/rubocop/cop/lint/number_conversion.rb
Expand Up @@ -58,8 +58,8 @@ class NumberConversion < Base
}.freeze
MSG = 'Replace unsafe number conversion with number '\
'class parsing, instead of using '\
'%<current>s, use stricter '\
'%<corrected_method>s.'
'`%<current>s`, use stricter '\
'`%<corrected_method>s`.'
METHODS = CONVERSION_METHOD_CLASS_MAPPING.keys.map(&:inspect).join(' ')

# @!method to_method(node)
Expand Down
28 changes: 14 additions & 14 deletions spec/rubocop/cop/lint/number_conversion_spec.rb
Expand Up @@ -5,7 +5,7 @@
it 'when using `#to_i`' do
expect_offense(<<~RUBY)
"10".to_i
^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using "10".to_i, use stricter Integer("10", 10).
^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `"10".to_i`, use stricter `Integer("10", 10)`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -16,7 +16,7 @@
it 'when using `#to_i` for integer' do
expect_offense(<<~RUBY)
10.to_i
^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using 10.to_i, use stricter Integer(10, 10).
^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `10.to_i`, use stricter `Integer(10, 10)`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -27,7 +27,7 @@
it 'when using `#to_f`' do
expect_offense(<<~RUBY)
"10.2".to_f
^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using "10.2".to_f, use stricter Float("10.2").
^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `"10.2".to_f`, use stricter `Float("10.2")`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -38,7 +38,7 @@
it 'when using `#to_c`' do
expect_offense(<<~RUBY)
"10".to_c
^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using "10".to_c, use stricter Complex("10").
^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `"10".to_c`, use stricter `Complex("10")`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -50,7 +50,7 @@
expect_offense(<<~RUBY)
string_value = '10'
string_value.to_i
^^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using string_value.to_i, use stricter Integer(string_value, 10).
^^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `string_value.to_i`, use stricter `Integer(string_value, 10)`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -63,7 +63,7 @@
expect_offense(<<~RUBY)
params = { id: 10 }
params[:id].to_i
^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using params[:id].to_i, use stricter Integer(params[:id], 10).
^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `params[:id].to_i`, use stricter `Integer(params[:id], 10)`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -76,7 +76,7 @@
expect_offense(<<~RUBY)
args = [1,2,3]
args[0].to_i
^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using args[0].to_i, use stricter Integer(args[0], 10).
^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `args[0].to_i`, use stricter `Integer(args[0], 10)`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -88,7 +88,7 @@
it 'when `#to_i` called on a variable on a hash' do
expect_offense(<<~RUBY)
params[:field].to_i
^^^^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using params[:field].to_i, use stricter Integer(params[:field], 10).
^^^^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `params[:field].to_i`, use stricter `Integer(params[:field], 10)`.
RUBY

expect_correction(<<~RUBY)
Expand Down Expand Up @@ -127,7 +127,7 @@
it 'registers offense and autocorrects' do
expect_offense(<<~RUBY)
"1,2,3,foo,5,6,7,8".split(',').map(&:to_i)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using &:to_i, use stricter { |i| Integer(i, 10) }.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `&:to_i`, use stricter `{ |i| Integer(i, 10) }`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -138,7 +138,7 @@
it 'registers offense and autocorrects without parentheses' do
expect_offense(<<~RUBY)
"1,2,3,foo,5,6,7,8".split(',').map &:to_i
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using &:to_i, use stricter { |i| Integer(i, 10) }.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `&:to_i`, use stricter `{ |i| Integer(i, 10) }`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -149,7 +149,7 @@
it 'registers offense with try' do
expect_offense(<<~RUBY)
"foo".try(:to_f)
^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using :to_f, use stricter { |i| Float(i) }.
^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `:to_f`, use stricter `{ |i| Float(i) }`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -160,7 +160,7 @@
it 'registers offense with send' do
expect_offense(<<~RUBY)
"foo".send(:to_c)
^^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using :to_c, use stricter { |i| Complex(i) }.
^^^^^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `:to_c`, use stricter `{ |i| Complex(i) }`.
RUBY

expect_correction(<<~RUBY)
Expand Down Expand Up @@ -216,7 +216,7 @@
it 'registers an offense for other methods' do
expect_offense(<<~RUBY)
10.hours.to_i
^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using 10.hours.to_i, use stricter Integer(10.hours, 10).
^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `10.hours.to_i`, use stricter `Integer(10.hours, 10)`.
RUBY
end
end
Expand All @@ -233,7 +233,7 @@
it 'registers an offense for other methods' do
expect_offense(<<~RUBY)
10.hours.to_i
^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using 10.hours.to_i, use stricter Integer(10.hours, 10).
^^^^^^^^^^^^^ Replace unsafe number conversion with number class parsing, instead of using `10.hours.to_i`, use stricter `Integer(10.hours, 10)`.
RUBY
end
end
Expand Down

0 comments on commit 464c4df

Please sign in to comment.