Safely autocorrect Lint/AmbiguousOperatorPrecedence

Inspecting 1480 files
...................................................................................................................................................................................................................................W..........................W........................................................W................W..............W................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Offenses:

app/models/calculator/flexi_rate.rb:38:7: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity.
      count * preferred_additional_item.to_f + preferred_first_item.to_f
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:362:12: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity.
    cat << "sells_" + sells
           ^^^^^^^^^^^^^^^^
app/models/enterprise.rb:496:21: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity.
    phone_number && "https://wa.me/" + phone_number.tr('+ ', '')
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/ability.rb:27:33: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity.
          order.user == user || order.token && token == order.token
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/ability.rb:30:33: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity.
          order.user == user || order.token && token == order.token
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/line_item.rb:205:16: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity.
      (price + fees / quantity).round(2)
               ^^^^^^^^^^^^^^^
app/models/spree/preferences/store.rb:28:11: W: [Corrected] Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity.
          should_persist? && Spree::Preference.where(key: key).exists?
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1480 files inspected, 7 offenses detected, 7 offenses corrected
This commit is contained in:
Neal Chambers
2023-07-28 16:45:10 +09:00
parent 0bcde2dbda
commit e9f448fad9
6 changed files with 9 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1400 --no-auto-gen-timestamp`
# using RuboCop version 1.54.2.
# using RuboCop version 1.55.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
@@ -34,16 +34,6 @@ Layout/LineLength:
- 'spec/system/consumer/shopping/cart_spec.rb'
- 'spec/system/consumer/shopping/products_spec.rb'
# Offense count: 7
# This cop supports safe autocorrection (--autocorrect).
Lint/AmbiguousOperatorPrecedence:
Exclude:
- 'app/models/calculator/flexi_rate.rb'
- 'app/models/enterprise.rb'
- 'app/models/spree/ability.rb'
- 'app/models/spree/line_item.rb'
- 'app/models/spree/preferences/store.rb'
# Offense count: 17
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
@@ -1144,7 +1134,7 @@ Style/HashAsLastArrayItem:
- 'app/components/products_table_component.rb'
# Offense count: 12
# This cop supports safe autocorrection (--autocorrect).
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowSplatArgument.
Style/HashConversion:
Exclude:

View File

@@ -35,7 +35,7 @@ module Calculator
private
def compute_for(count)
count * preferred_additional_item.to_f + preferred_first_item.to_f
(count * preferred_additional_item.to_f) + preferred_first_item.to_f
end
end
end

View File

@@ -359,7 +359,7 @@ class Enterprise < ApplicationRecord
def category
# Make this crazy logic human readable so we can argue about it sanely.
cat = is_primary_producer ? "producer_" : "non_producer_"
cat << "sells_" + sells
cat << ("sells_" + sells)
# Map backend cases to front end cases.
case cat
@@ -493,7 +493,7 @@ class Enterprise < ApplicationRecord
end
def correct_whatsapp_url(phone_number)
phone_number && "https://wa.me/" + phone_number.tr('+ ', '')
phone_number && ("https://wa.me/" + phone_number.tr('+ ', ''))
end
def correct_instagram_url(url)

View File

@@ -24,10 +24,10 @@ module Spree
can [:index, :read], Country
can :create, Order
can :read, Order do |order, token|
order.user == user || order.token && token == order.token
order.user == user || (order.token && token == order.token)
end
can :update, Order do |order, token|
order.user == user || order.token && token == order.token
order.user == user || (order.token && token == order.token)
end
can [:index, :read], Product
can [:index, :read], ProductProperty

View File

@@ -202,7 +202,7 @@ module Spree
fees = adjustments.enterprise_fee.sum(:amount)
(price + fees / quantity).round(2)
(price + (fees / quantity)).round(2)
end
def single_display_amount_with_adjustments

View File

@@ -25,7 +25,7 @@ module Spree
def exist?(key)
@cache.exist?(key) ||
should_persist? && Spree::Preference.where(key: key).exists?
(should_persist? && Spree::Preference.where(key: key).exists?)
end
def get(key, fallback = nil)