From 281c73a8ed8ecebd8c7280dee6c6b1016ed32eb5 Mon Sep 17 00:00:00 2001 From: Yoshiyuki Hirano Date: Tue, 3 Apr 2018 22:25:16 +0900 Subject: [PATCH] Update Rubocop to v0.54.0 - 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` --- .rubocop_todo.yml | 23 ++++---- .travis.yml | 2 +- core/time/at_spec.rb | 2 +- library/bigdecimal/divmod_spec.rb | 6 +- library/bigdecimal/inspect_spec.rb | 2 +- library/bigdecimal/new_spec.rb | 90 ++++++++++++++--------------- library/bigdecimal/shared/eql.rb | 4 +- library/bigdecimal/shared/modulo.rb | 6 +- library/bigdecimal/to_r_spec.rb | 2 +- library/bigdecimal/to_s_spec.rb | 24 ++++---- 10 files changed, 81 insertions(+), 80 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5fc8c91a85..9484078c8e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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 @@ -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: @@ -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 @@ -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 @@ -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: @@ -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' @@ -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 diff --git a/.travis.yml b/.travis.yml index e6337e1b00..3d20fb7065 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/core/time/at_spec.rb b/core/time/at_spec.rb index 8363a0bc70..7c66104156 100644 --- a/core/time/at_spec.rb +++ b/core/time/at_spec.rb @@ -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 diff --git a/library/bigdecimal/divmod_spec.rb b/library/bigdecimal/divmod_spec.rb index a93e0836bf..22b66c2d48 100644 --- a/library/bigdecimal/divmod_spec.rb +++ b/library/bigdecimal/divmod_spec.rb @@ -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) @@ -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 diff --git a/library/bigdecimal/inspect_spec.rb b/library/bigdecimal/inspect_spec.rb index 0873e8bef6..7e1a8297e2 100644 --- a/library/bigdecimal/inspect_spec.rb +++ b/library/bigdecimal/inspect_spec.rb @@ -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 diff --git a/library/bigdecimal/new_spec.rb b/library/bigdecimal/new_spec.rb index 64f2a7f468..0bf964d804 100644 --- a/library/bigdecimal/new_spec.rb +++ b/library/bigdecimal/new_spec.rb @@ -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 diff --git a/library/bigdecimal/shared/eql.rb b/library/bigdecimal/shared/eql.rb index eaad272e9a..8e3e388bab 100644 --- a/library/bigdecimal/shared/eql.rb +++ b/library/bigdecimal/shared/eql.rb @@ -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") diff --git a/library/bigdecimal/shared/modulo.rb b/library/bigdecimal/shared/modulo.rb index 78ebe8360d..c9691cbf37 100644 --- a/library/bigdecimal/shared/modulo.rb +++ b/library/bigdecimal/shared/modulo.rb @@ -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") @@ -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) diff --git a/library/bigdecimal/to_r_spec.rb b/library/bigdecimal/to_r_spec.rb index e2956782bd..91d2b33993 100644 --- a/library/bigdecimal/to_r_spec.rb +++ b/library/bigdecimal/to_r_spec.rb @@ -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 diff --git a/library/bigdecimal/to_s_spec.rb b/library/bigdecimal/to_s_spec.rb index 86716c93fe..86ae1e61f6 100644 --- a/library/bigdecimal/to_s_spec.rb +++ b/library/bigdecimal/to_s_spec.rb @@ -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 @@ -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 @@ -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