diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ea6d12eabb..8e413c6b89 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,52 +6,13 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: AllowSafeAssignment. -Lint/AssignmentInCondition: - Exclude: - - 'lib/money/bank/variable_exchange.rb' - -Lint/FloatComparison: - Exclude: - - 'spec/money/arithmetic_spec.rb' - -# This cop supports safe autocorrection (--autocorrect). -Lint/ImplicitStringConcatenation: - Exclude: - - 'spec/money/formatting_spec.rb' - -# Configuration parameters: AllowedParentClasses. -Lint/MissingSuper: - Exclude: - - 'lib/money/locale_backend/i18n.rb' - - 'lib/money/money.rb' - -# Configuration parameters: AllowComments, AllowNil. -Lint/SuppressedException: - Exclude: - - 'lib/money/money/arithmetic.rb' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods, NotImplementedExceptions. -# NotImplementedExceptions: NotImplementedError -Lint/UnusedMethodArgument: - Exclude: - - 'lib/money/bank/variable_exchange.rb' - - 'lib/money/currency/heuristics.rb' - -# This cop supports safe autocorrection (--autocorrect). -Lint/UselessAssignment: - Exclude: - - 'lib/money/money/formatter.rb' - # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 34 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 230 + Max: 231 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: @@ -63,7 +24,7 @@ Metrics/MethodLength: # Configuration parameters: CountComments, CountAsOne. Metrics/ModuleLength: - Max: 140 + Max: 141 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: diff --git a/lib/money/bank/variable_exchange.rb b/lib/money/bank/variable_exchange.rb index 14ea37411e..e42e46fc26 100644 --- a/lib/money/bank/variable_exchange.rb +++ b/lib/money/bank/variable_exchange.rb @@ -112,7 +112,7 @@ def exchange_with(from, to_currency, &) if from.currency == to_currency from else - if rate = get_rate(from.currency, to_currency) + if (rate = get_rate(from.currency, to_currency)) fractional = calculate_fractional(from, to_currency) from.dup_with( fractional: exchange(fractional, rate, &), @@ -175,7 +175,7 @@ def add_rate(from, to, rate) # bank = Money::Bank::VariableExchange.new # bank.set_rate("USD", "CAD", 1.24515) # bank.set_rate("CAD", "USD", 0.803115) - def set_rate(from, to, rate, opts = {}) + def set_rate(from, to, rate, _opts = {}) store.add_rate(Currency.wrap(from).iso_code, Currency.wrap(to).iso_code, rate) end @@ -196,7 +196,7 @@ def set_rate(from, to, rate, opts = {}) # # bank.get_rate("USD", "CAD") #=> 1.24515 # bank.get_rate("CAD", "USD") #=> 0.803115 - def get_rate(from, to, opts = {}) + def get_rate(from, to, _opts = {}) store.get_rate(Currency.wrap(from).iso_code, Currency.wrap(to).iso_code) end @@ -219,7 +219,7 @@ def get_rate(from, to, opts = {}) # # s = bank.export_rates(:json) # s #=> "{\"USD_TO_CAD\":1.24515,\"CAD_TO_USD\":0.803115}" - def export_rates(format, file = nil, opts = {}) + def export_rates(format, file = nil, _opts = {}) raise Money::Bank::UnknownRateFormat unless RATE_FORMATS.include?(format) store.transaction do @@ -259,7 +259,7 @@ def rates # # bank.get_rate("USD", "CAD") #=> 1.24515 # bank.get_rate("CAD", "USD") #=> 0.803115 - def import_rates(format, string, opts = {}) + def import_rates(format, string, _opts = {}) raise Money::Bank::UnknownRateFormat unless RATE_FORMATS.include?(format) if format == :ruby diff --git a/lib/money/currency/heuristics.rb b/lib/money/currency/heuristics.rb index 4cae8d9cb5..7964995242 100644 --- a/lib/money/currency/heuristics.rb +++ b/lib/money/currency/heuristics.rb @@ -3,7 +3,7 @@ class Money class Currency module Heuristics - def analyze(str) + def analyze(_str) raise StandardError, 'Heuristics deprecated, add `gem "money-heuristics"` to Gemfile' end end diff --git a/lib/money/locale_backend/i18n.rb b/lib/money/locale_backend/i18n.rb index fdad3cb905..0e41adc9ad 100644 --- a/lib/money/locale_backend/i18n.rb +++ b/lib/money/locale_backend/i18n.rb @@ -14,6 +14,8 @@ class I18n < Base def initialize raise NotSupported, 'I18n not found' unless defined?(::I18n) + + super end def lookup(key, _) diff --git a/lib/money/money.rb b/lib/money/money.rb index e49c4ccc59..6af38ee160 100644 --- a/lib/money/money.rb +++ b/lib/money/money.rb @@ -242,6 +242,8 @@ def self.setup_defaults def self.inherited(base) base.setup_defaults + + super end setup_defaults diff --git a/lib/money/money/arithmetic.rb b/lib/money/money/arithmetic.rb index 6245f37a00..904260971a 100644 --- a/lib/money/money/arithmetic.rb +++ b/lib/money/money/arithmetic.rb @@ -77,6 +77,7 @@ def <=>(other) other = other.exchange_to(currency) fractional <=> other.fractional rescue Money::Bank::UnknownRate + nil end # Uses Comparable's implementation but raises ArgumentError if non-zero diff --git a/lib/money/money/formatter.rb b/lib/money/money/formatter.rb index 7903563b48..2b0c2598c4 100644 --- a/lib/money/money/formatter.rb +++ b/lib/money/money/formatter.rb @@ -262,7 +262,7 @@ def append_sign(formatted_number) .gsub('%u', [sign_before, symbol_value].join) .gsub('%n', [sign, formatted_number].join) else - formatted_number = "#{sign_before}#{sign}#{formatted_number}" + "#{sign_before}#{sign}#{formatted_number}" end end diff --git a/spec/money/arithmetic_spec.rb b/spec/money/arithmetic_spec.rb index 206901c3ba..fbf8f00680 100644 --- a/spec/money/arithmetic_spec.rb +++ b/spec/money/arithmetic_spec.rb @@ -56,11 +56,13 @@ expect(Money.new(1, "USD")).not_to eq 0 end + # rubocop:disable Lint/FloatComparison it 'raises error for non-zero numerics' do expect { Money.new(1_00, "USD") == 1 }.to raise_error ArgumentError expect { Money.new(1_00, "USD") == -2.0 }.to raise_error ArgumentError expect { Money.new(1_00, "USD") == Float::INFINITY }.to raise_error ArgumentError end + # rubocop:enable Lint/FloatComparison end describe "#eql?" do @@ -110,6 +112,7 @@ end end + # rubocop:disable Lint/FloatComparison it "returns false if used to compare with an object that doesn't inherit from Money" do expect(Money.new(1_00, "USD").eql?(Object.new)).to be false expect(Money.new(1_00, "USD").eql?(Class)).to be false @@ -120,6 +123,7 @@ expect(Money.new(1_00, "USD").eql?(1)).to be false expect(Money.new(1_00, "USD").eql?(1_00)).to be false end + # rubocop:enable Lint/FloatComparison it "can be used to compare with an object that inherits from Money" do klass = Class.new(Money) diff --git a/spec/money/formatting_spec.rb b/spec/money/formatting_spec.rb index fb1e50758a..daf43ff803 100644 --- a/spec/money/formatting_spec.rb +++ b/spec/money/formatting_spec.rb @@ -340,7 +340,7 @@ expect(Money.new(100, "SEK").format(symbol: true)).to eq "1,00 kr" end - specify "(symbol: "", nil or false) returns the amount without a symbol" do + specify "(symbol: \"\", nil or false) returns the amount without a symbol" do money = Money.new(100, "GBP") expect(money.format(symbol: "")).to eq "1.00" expect(money.format(symbol: nil)).to eq "1.00"