Safely autocorrect Style/FetchEnvVar

Inspecting 1483 files
..............................................................................................................................................................C.............................................................................................................................................................................CC.............................................................................................................................................................................C.................................................................................................................................................................................................................................................................................................................................................................C.................................................................................C..............................................................................................................................................................................................C.....................................................................................................................................................................................................................................C......................................................................................................................

Offenses:

app/helpers/discourse_helper.rb:9:5: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('DISCOURSE_URL') or ENV.fetch('DISCOURSE_URL', nil) instead of ENV['DISCOURSE_URL'].
    ENV['DISCOURSE_URL']
    ^^^^^^^^^^^^^^^^^^^^
app/models/spree/preferences/configuration.rb:35:10: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('RAILS_CACHE_ID') or ENV.fetch('RAILS_CACHE_ID', nil) instead of ENV['RAILS_CACHE_ID'].
        [ENV['RAILS_CACHE_ID'], self.class.name, name].flatten.join('::').underscore
         ^^^^^^^^^^^^^^^^^^^^^
app/models/spree/preferences/preferable.rb:84:10: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch("RAILS_CACHE_ID") or ENV.fetch("RAILS_CACHE_ID", nil) instead of ENV["RAILS_CACHE_ID"].
        [ENV["RAILS_CACHE_ID"], self.class.name, name, id].join('::').underscore
         ^^^^^^^^^^^^^^^^^^^^^
app/services/default_country.rb:13:40: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch("DEFAULT_COUNTRY_CODE") or ENV.fetch("DEFAULT_COUNTRY_CODE", nil) instead of ENV["DEFAULT_COUNTRY_CODE"].
    Spree::Country.cached_find_by(iso: ENV["DEFAULT_COUNTRY_CODE"]) || Spree::Country.first
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/default_country.rb:13:73: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
    Spree::Country.cached_find_by(iso: ENV.fetch("DEFAULT_COUNTRY_CODE",
                                                                        ^
app/services/default_country.rb:13:101: C: [Corrected] Layout/LineLength: Line is too long. [102/100]
    Spree::Country.cached_find_by(iso: ENV.fetch("DEFAULT_COUNTRY_CODE", nil)) || Spree::Country.first
                                                                                                    ^^
app/services/default_country.rb:14:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
nil)) || Spree::Country.first
^^^
spec/base_spec_helper.rb:51:49: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch("SITE_URL") or ENV.fetch("SITE_URL", nil) instead of ENV["SITE_URL"].
ActionMailer::Base.default_url_options[:host] = ENV["SITE_URL"]
                                                ^^^^^^^^^^^^^^^
spec/controllers/spree/credit_cards_controller_spec.rb:8:20: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('STRIPE_SECRET_TEST_API_KEY') or ENV.fetch('STRIPE_SECRET_TEST_API_KEY', nil) instead of ENV['STRIPE_SECRET_TEST_API_KEY'].
    let(:secret) { ENV['STRIPE_SECRET_TEST_API_KEY'] }
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/order_balance_spec.rb:48:70: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      expect(order_balance.display_amount).to eq(Spree::Money.new(20,
                                                                     ^
spec/models/order_balance_spec.rb:48:81: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('currency') or ENV.fetch('currency', nil) instead of ENV['currency'].
      expect(order_balance.display_amount).to eq(Spree::Money.new(20, currency: ENV['currency']))
                                                                                ^^^^^^^^^^^^^^^
spec/models/order_balance_spec.rb:48:101: C: [Corrected] Layout/LineLength: Line is too long. [108/100]
      expect(order_balance.display_amount).to eq(Spree::Money.new(20, currency: ENV.fetch('currency', nil)))
                                                                                                    ^^^^^^^^
spec/models/order_balance_spec.rb:49:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
currency: ENV.fetch('currency', nil)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/order_balance_spec.rb:49:98: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
                                                                  currency: ENV.fetch('currency',
                                                                                                 ^
spec/models/order_balance_spec.rb:49:101: C: [Corrected] Layout/LineLength: Line is too long. [104/100]
                                                                  currency: ENV.fetch('currency', nil)))
                                                                                                    ^^^^
spec/models/order_balance_spec.rb:50:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
nil)))
^^^
spec/support/vcr_setup.rb:10:50: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('STRIPE_SECRET_TEST_API_KEY') or ENV.fetch('STRIPE_SECRET_TEST_API_KEY', nil) instead of ENV['STRIPE_SECRET_TEST_API_KEY'].
  config.filter_sensitive_data('<HIDDEN_KEY>') { ENV['STRIPE_SECRET_TEST_API_KEY'] }
                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/support/vcr_setup.rb:11:55: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('STRIPE_CUSTOMER') or ENV.fetch('STRIPE_CUSTOMER', nil) instead of ENV['STRIPE_CUSTOMER'].
  config.filter_sensitive_data('<HIDDEN_CUSTOMER>') { ENV['STRIPE_CUSTOMER'] }
                                                      ^^^^^^^^^^^^^^^^^^^^^^

1483 files inspected, 18 offenses detected, 18 offenses corrected
This commit is contained in:
Neal Chambers
2023-08-17 13:55:58 +09:00
parent fd795d8513
commit bc559b966c
9 changed files with 20 additions and 23 deletions

View File

@@ -6,6 +6,14 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Exclude:
- 'spec/system/admin/tag_rules_spec.rb'
# Offense count: 17
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
@@ -801,20 +809,6 @@ Style/ClassVars:
Exclude:
- 'lib/spree/core/delegate_belongs_to.rb'
# Offense count: 9
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowedVars.
Style/FetchEnvVar:
Exclude:
- 'app/helpers/discourse_helper.rb'
- 'app/models/spree/preferences/configuration.rb'
- 'app/models/spree/preferences/preferable.rb'
- 'app/services/default_country.rb'
- 'spec/base_spec_helper.rb'
- 'spec/controllers/spree/credit_cards_controller_spec.rb'
- 'spec/models/order_balance_spec.rb'
- 'spec/support/vcr_setup.rb'
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Style/FileRead:

View File

@@ -6,7 +6,7 @@ module DiscourseHelper
end
def discourse_url
ENV['DISCOURSE_URL']
ENV.fetch('DISCOURSE_URL', nil)
end
def discourse_login_url

View File

@@ -32,7 +32,7 @@ module Spree
end
def preference_cache_key(name)
[ENV['RAILS_CACHE_ID'], self.class.name, name].flatten.join('::').underscore
[ENV.fetch('RAILS_CACHE_ID', nil), self.class.name, name].flatten.join('::').underscore
end
def reset

View File

@@ -81,7 +81,7 @@ module Spree
def preference_cache_key(name)
return unless id
[ENV["RAILS_CACHE_ID"], self.class.name, name, id].join('::').underscore
[ENV.fetch("RAILS_CACHE_ID", nil), self.class.name, name, id].join('::').underscore
end
def save_pending_preferences

View File

@@ -10,6 +10,7 @@ class DefaultCountry
end
def self.country
Spree::Country.cached_find_by(iso: ENV["DEFAULT_COUNTRY_CODE"]) || Spree::Country.first
Spree::Country.cached_find_by(iso: ENV.fetch("DEFAULT_COUNTRY_CODE",
nil)) || Spree::Country.first
end
end

View File

@@ -48,7 +48,7 @@ Capybara.configure do |config|
end
# Override setting in Spree engine: Spree::Core::MailSettings
ActionMailer::Base.default_url_options[:host] = ENV["SITE_URL"]
ActionMailer::Base.default_url_options[:host] = ENV.fetch("SITE_URL", nil)
FactoryBot.use_parent_strategy = false
FactoryBot::SyntaxRunner.include FileHelper

View File

@@ -5,7 +5,7 @@ require 'spec_helper'
describe Spree::CreditCardsController, type: :controller do
describe "using VCR", :vcr do
let(:user) { create(:user) }
let(:secret) { ENV['STRIPE_SECRET_TEST_API_KEY'] }
let(:secret) { ENV.fetch('STRIPE_SECRET_TEST_API_KEY', nil) }
before do
Stripe.api_key = secret

View File

@@ -45,7 +45,9 @@ describe OrderBalance do
end
it 'returns the balance wraped in a Money object' do
expect(order_balance.display_amount).to eq(Spree::Money.new(20, currency: ENV['currency']))
expect(order_balance.display_amount).to eq(Spree::Money.new(20,
currency: ENV.fetch('currency',
nil)))
end
end

View File

@@ -7,7 +7,7 @@ VCR.configure do |config|
config.hook_into :webmock
config.ignore_localhost = true
config.configure_rspec_metadata!
config.filter_sensitive_data('<HIDDEN_KEY>') { ENV['STRIPE_SECRET_TEST_API_KEY'] }
config.filter_sensitive_data('<HIDDEN_CUSTOMER>') { ENV['STRIPE_CUSTOMER'] }
config.filter_sensitive_data('<HIDDEN_KEY>') { ENV.fetch('STRIPE_SECRET_TEST_API_KEY', nil) }
config.filter_sensitive_data('<HIDDEN_CUSTOMER>') { ENV.fetch('STRIPE_CUSTOMER', nil) }
config.ignore_hosts('localhost', '127.0.0.1', '0.0.0.0', 'api.knapsackpro.com')
end