Skip to content

Commit

Permalink
Update Rubocop to v0.54.0
Browse files Browse the repository at this point in the history
- Update rubocop version in .travis.yml
- Fix rubocop offenses:
  - Lint/BigDecimalNew
    - BigDecimal.new() is deprecated since BigDecimal 1.3.3 for Ruby 2.5
    - So it worth to enable, I think.
- Re-execute `rubocop --auto-gen-config`
  • Loading branch information
yhirano55 authored and eregon committed Apr 3, 2018
1 parent f6a59dc commit 281c73a
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 80 deletions.
23 changes: 12 additions & 11 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-12-15 22:14:22 +0900 using RuboCop version 0.52.0.
# on 2018-04-03 22:23:59 +0900 using RuboCop version 0.54.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -20,11 +20,6 @@ Lint/DuplicateMethods:
- 'core/unboundmethod/fixtures/classes.rb'
- 'fixtures/class.rb'

# Offense count: 4
Lint/EmptyWhen:
Exclude:
- 'language/case_spec.rb'

# Offense count: 5
Lint/EnsureReturn:
Exclude:
Expand All @@ -43,7 +38,7 @@ Lint/FormatParameterMismatch:
- 'core/kernel/shared/sprintf.rb'
- 'core/string/modulo_spec.rb'

# Offense count: 28
# Offense count: 29
Lint/HandleExceptions:
Enabled: false

Expand All @@ -59,7 +54,7 @@ Lint/IneffectiveAccessModifier:
- 'core/module/fixtures/classes.rb'
- 'language/fixtures/private.rb'

# Offense count: 5
# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: runtime_error, standard_error
Expand All @@ -69,13 +64,13 @@ Lint/InheritException:
- 'core/exception/fixtures/common.rb'
- 'core/module/fixtures/autoload_ex1.rb'

# Offense count: 3
# Offense count: 5
# Cop supports --auto-correct.
Lint/LiteralInInterpolation:
Exclude:
- 'core/module/refine_spec.rb'
- 'language/defined_spec.rb'
- 'language/fixtures/squiggly_heredoc.rb'
- 'core/module/refine_spec.rb'

# Offense count: 16
Lint/Loop:
Expand Down Expand Up @@ -105,7 +100,7 @@ Lint/RedundantWithIndex:
Exclude:
- 'core/enumerator/with_index_spec.rb'

# Offense count: 24
# Offense count: 26
Lint/RescueException:
Exclude:
- 'command_line/fixtures/debug_info.rb'
Expand Down Expand Up @@ -200,3 +195,9 @@ Lint/UselessAccessModifier:
- 'core/module/module_function_spec.rb'
- 'core/module/private_class_method_spec.rb'
- 'language/fixtures/send.rb'

# Offense count: 6186
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 588
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ matrix:
- env: RUBOCOP=true
rvm: 2.4.4
script:
- gem install rubocop -v 0.52.0
- gem install rubocop -v 0.54.0
- rubocop
allow_failures:
- rvm: ruby-head
Expand Down
2 changes: 1 addition & 1 deletion core/time/at_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
describe "passed BigDecimal" do
it "doesn't round input value" do
require 'bigdecimal'
Time.at(BigDecimal.new('1.1')).to_f.should == 1.1
Time.at(BigDecimal('1.1')).to_f.should == 1.1
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions library/bigdecimal/divmod_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BigDecimal
it_behaves_like :bigdecimal_modulo, :mod_part_of_divmod

it "raises ZeroDivisionError if other is zero" do
bd5667 = BigDecimal.new("5667.19")
bd5667 = BigDecimal("5667.19")

lambda { bd5667.send(@method, 0) }.should raise_error(ZeroDivisionError)
lambda { bd5667.send(@method, BigDecimal("0")) }.should raise_error(ZeroDivisionError)
Expand Down Expand Up @@ -96,8 +96,8 @@ class BigDecimal

it "can be reversed with * and +" do
# Example taken from BigDecimal documentation
a = BigDecimal.new("42")
b = BigDecimal.new("9")
a = BigDecimal("42")
b = BigDecimal("9")
q, m = a.divmod(b)
c = q * b + m
a.should == c
Expand Down
2 changes: 1 addition & 1 deletion library/bigdecimal/inspect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
describe "BigDecimal#inspect" do

before :each do
@bigdec = BigDecimal.new("1234.5678")
@bigdec = BigDecimal("1234.5678")
end

it "returns String" do
Expand Down
90 changes: 45 additions & 45 deletions library/bigdecimal/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,102 +4,102 @@
describe "BigDecimal.new" do

it "creates a new object of class BigDecimal" do
BigDecimal.new("3.14159").should be_kind_of(BigDecimal)
BigDecimal("3.14159").should be_kind_of(BigDecimal)
(0..9).each {|i|
BigDecimal.new("1#{i}").should == 10 + i
BigDecimal.new("-1#{i}").should == -10 - i
BigDecimal.new("1E#{i}").should == 10**i
BigDecimal.new("1000000E-#{i}").should == 10**(6-i).to_f
BigDecimal("1#{i}").should == 10 + i
BigDecimal("-1#{i}").should == -10 - i
BigDecimal("1E#{i}").should == 10**i
BigDecimal("1000000E-#{i}").should == 10**(6-i).to_f
# ^ to_f to avoid Rational type
}
(1..9).each {|i|
BigDecimal.new("100.#{i}").to_s.should =~ /\A0\.100#{i}E3\z/i
BigDecimal.new("-100.#{i}").to_s.should =~ /\A-0\.100#{i}E3\z/i
BigDecimal("100.#{i}").to_s.should =~ /\A0\.100#{i}E3\z/i
BigDecimal("-100.#{i}").to_s.should =~ /\A-0\.100#{i}E3\z/i
}
end

it "accepts significant digits >= given precision" do
BigDecimal.new("3.1415923", 10).precs[1].should >= 10
BigDecimal("3.1415923", 10).precs[1].should >= 10
end

it "determines precision from initial value" do
pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
BigDecimal.new(pi_string).precs[1].should >= pi_string.size-1
BigDecimal(pi_string).precs[1].should >= pi_string.size-1
end

it "ignores leading whitespace" do
BigDecimal.new(" \t\n \r1234").should == BigDecimal.new("1234")
BigDecimal.new(" \t\n \rNaN \n").nan?.should == true
BigDecimal.new(" \t\n \rInfinity \n").infinite?.should == 1
BigDecimal.new(" \t\n \r-Infinity \n").infinite?.should == -1
BigDecimal(" \t\n \r1234").should == BigDecimal("1234")
BigDecimal(" \t\n \rNaN \n").nan?.should == true
BigDecimal(" \t\n \rInfinity \n").infinite?.should == 1
BigDecimal(" \t\n \r-Infinity \n").infinite?.should == -1
end

it "ignores trailing garbage" do
BigDecimal.new("123E45ruby").should == BigDecimal.new("123E45")
BigDecimal.new("123x45").should == BigDecimal.new("123")
BigDecimal.new("123.4%E5").should == BigDecimal.new("123.4")
BigDecimal.new("1E2E3E4E5E").should == BigDecimal.new("100")
BigDecimal("123E45ruby").should == BigDecimal("123E45")
BigDecimal("123x45").should == BigDecimal("123")
BigDecimal("123.4%E5").should == BigDecimal("123.4")
BigDecimal("1E2E3E4E5E").should == BigDecimal("100")
end

ruby_version_is ""..."2.4" do
it "treats invalid strings as 0.0" do
BigDecimal.new("ruby").should == BigDecimal.new("0.0")
BigDecimal.new(" \t\n \r-\t\t\tInfinity \n").should == BigDecimal.new("0.0")
BigDecimal("ruby").should == BigDecimal("0.0")
BigDecimal(" \t\n \r-\t\t\tInfinity \n").should == BigDecimal("0.0")
end
end

ruby_version_is "2.4" do
it "raises ArgumentError for invalid strings" do
lambda { BigDecimal.new("ruby") }.should raise_error(ArgumentError)
lambda { BigDecimal.new(" \t\n \r-\t\t\tInfinity \n") }.should raise_error(ArgumentError)
lambda { BigDecimal("ruby") }.should raise_error(ArgumentError)
lambda { BigDecimal(" \t\n \r-\t\t\tInfinity \n") }.should raise_error(ArgumentError)
end
end

it "allows omitting the integer part" do
BigDecimal.new(".123").should == BigDecimal.new("0.123")
BigDecimal(".123").should == BigDecimal("0.123")
end

it "allows for underscores in all parts" do
reference = BigDecimal.new("12345.67E89")
reference = BigDecimal("12345.67E89")

BigDecimal.new("12_345.67E89").should == reference
BigDecimal.new("1_2_3_4_5_._6____7_E89").should == reference
BigDecimal.new("12345_.67E_8__9_").should == reference
BigDecimal("12_345.67E89").should == reference
BigDecimal("1_2_3_4_5_._6____7_E89").should == reference
BigDecimal("12345_.67E_8__9_").should == reference
end

it "accepts NaN and [+-]Infinity" do
BigDecimal.new("NaN").nan?.should == true
BigDecimal("NaN").nan?.should == true

pos_inf = BigDecimal.new("Infinity")
pos_inf = BigDecimal("Infinity")
pos_inf.finite?.should == false
pos_inf.should > 0
pos_inf.should == BigDecimal.new("+Infinity")
pos_inf.should == BigDecimal("+Infinity")

neg_inf = BigDecimal.new("-Infinity")
neg_inf = BigDecimal("-Infinity")
neg_inf.finite?.should == false
neg_inf.should < 0
end

it "allows for [eEdD] as exponent separator" do
reference = BigDecimal.new("12345.67E89")
reference = BigDecimal("12345.67E89")

BigDecimal.new("12345.67e89").should == reference
BigDecimal.new("12345.67E89").should == reference
BigDecimal.new("12345.67d89").should == reference
BigDecimal.new("12345.67D89").should == reference
BigDecimal("12345.67e89").should == reference
BigDecimal("12345.67E89").should == reference
BigDecimal("12345.67d89").should == reference
BigDecimal("12345.67D89").should == reference
end

it "allows for varying signs" do
reference = BigDecimal.new("123.456E1")

BigDecimal.new("+123.456E1").should == reference
BigDecimal.new("-123.456E1").should == -reference
BigDecimal.new("123.456E+1").should == reference
BigDecimal.new("12345.6E-1").should == reference
BigDecimal.new("+123.456E+1").should == reference
BigDecimal.new("+12345.6E-1").should == reference
BigDecimal.new("-123.456E+1").should == -reference
BigDecimal.new("-12345.6E-1").should == -reference
reference = BigDecimal("123.456E1")

BigDecimal("+123.456E1").should == reference
BigDecimal("-123.456E1").should == -reference
BigDecimal("123.456E+1").should == reference
BigDecimal("12345.6E-1").should == reference
BigDecimal("+123.456E+1").should == reference
BigDecimal("+12345.6E-1").should == reference
BigDecimal("-123.456E+1").should == -reference
BigDecimal("-12345.6E-1").should == -reference
end

it 'raises ArgumentError when Float is used without precision' do
Expand Down
4 changes: 2 additions & 2 deletions library/bigdecimal/shared/eql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

describe :bigdecimal_eql, shared: true do
before :each do
@bg6543_21 = BigDecimal.new("6543.21")
@bg5667_19 = BigDecimal.new("5667.19")
@bg6543_21 = BigDecimal("6543.21")
@bg5667_19 = BigDecimal("5667.19")
@a = BigDecimal("1.0000000000000000000000000000000000000000005")
@b = BigDecimal("1.00000000000000000000000000000000000000000005")
@bigint = BigDecimal("1000.0")
Expand Down
6 changes: 3 additions & 3 deletions library/bigdecimal/shared/modulo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
end

it "returns self modulo other" do
bd6543 = BigDecimal.new("6543.21")
bd5667 = BigDecimal.new("5667.19")
bd6543 = BigDecimal("6543.21")
bd5667 = BigDecimal("5667.19")
a = BigDecimal("1.0000000000000000000000000000000000000000005")
b = BigDecimal("1.00000000000000000000000000000000000000000005")

Expand Down Expand Up @@ -107,7 +107,7 @@

describe :bigdecimal_modulo_zerodivisionerror, shared: true do
it "raises ZeroDivisionError if other is zero" do
bd5667 = BigDecimal.new("5667.19")
bd5667 = BigDecimal("5667.19")

lambda { bd5667.send(@method, 0) }.should raise_error(ZeroDivisionError)
lambda { bd5667.send(@method, BigDecimal("0")) }.should raise_error(ZeroDivisionError)
Expand Down
2 changes: 1 addition & 1 deletion library/bigdecimal/to_r_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

it "returns a Rational with bignum values" do
r = BigDecimal.new("3.141592653589793238462643").to_r
r = BigDecimal("3.141592653589793238462643").to_r
r.numerator.should eql(3141592653589793238462643)
r.denominator.should eql(1000000000000000000000000)
end
Expand Down
24 changes: 12 additions & 12 deletions library/bigdecimal/to_s_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
@bigdec.to_s(3).should =~ re

str1 = '-123.45678 90123 45678 9'
BigDecimal.new("-123.45678901234567890").to_s('5F').should == str1
BigDecimal("-123.45678901234567890").to_s('5F').should == str1
# trailing zeroes removed
BigDecimal.new("1.00000000000").to_s('1F').should == "1.0"
BigDecimal("1.00000000000").to_s('1F').should == "1.0"
# 0 is treated as no spaces
BigDecimal.new("1.2345").to_s('0F').should == "1.2345"
BigDecimal("1.2345").to_s('0F').should == "1.2345"
end

it "can return a leading space for values > 0" do
Expand All @@ -47,15 +47,15 @@
end

it "removes trailing spaces in floating point notation" do
BigDecimal.new('-123.45678901234567890').to_s('F').should == "-123.4567890123456789"
BigDecimal.new('1.2500').to_s('F').should == "1.25"
BigDecimal.new('0000.00000').to_s('F').should == "0.0"
BigDecimal.new('-00.000010000').to_s('F').should == "-0.00001"
BigDecimal.new("5.00000E-2").to_s("F").should == "0.05"
BigDecimal('-123.45678901234567890').to_s('F').should == "-123.4567890123456789"
BigDecimal('1.2500').to_s('F').should == "1.25"
BigDecimal('0000.00000').to_s('F').should == "0.0"
BigDecimal('-00.000010000').to_s('F').should == "-0.00001"
BigDecimal("5.00000E-2").to_s("F").should == "0.05"

BigDecimal.new("500000").to_s("F").should == "500000.0"
BigDecimal.new("5E2").to_s("F").should == "500.0"
BigDecimal.new("-5E100").to_s("F").should == "-5" + "0" * 100 + ".0"
BigDecimal("500000").to_s("F").should == "500000.0"
BigDecimal("5E2").to_s("F").should == "500.0"
BigDecimal("-5E100").to_s("F").should == "-5" + "0" * 100 + ".0"
end

it "can use engineering notation" do
Expand All @@ -66,7 +66,7 @@
@bigdec.to_s("F").should == @bigdec_str
@bigneg.to_s("F").should == @bigneg_str
str2 = "+123.45678901 23456789"
BigDecimal.new('123.45678901234567890').to_s('+8F').should == str2
BigDecimal('123.45678901234567890').to_s('+8F').should == str2
end

end
Expand Down

0 comments on commit 281c73a

Please sign in to comment.