Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routine Rubopcop lint fixes #17844

Merged
merged 4 commits into from Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/controllers/api/v0/health_checks_controller.rb
Expand Up @@ -39,10 +39,10 @@ def authenticate_with_token

def all_cache_instances_connected?
[
ENV["REDIS_URL"],
ENV["REDIS_SESSIONS_URL"],
ENV["REDIS_SIDEKIQ_URL"],
ENV["REDIS_RPUSH_URL"],
ENV.fetch("REDIS_URL", nil),
ENV.fetch("REDIS_SESSIONS_URL", nil),
ENV.fetch("REDIS_SIDEKIQ_URL", nil),
ENV.fetch("REDIS_RPUSH_URL", nil),
].compact.all? do |url|
Redis.new(url: url).ping == "PONG"
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/app_secrets.rb
Expand Up @@ -23,7 +23,7 @@ def self.vault_enabled?
end

def self.namespace
ENV["VAULT_SECRET_NAMESPACE"]
ENV.fetch("VAULT_SECRET_NAMESPACE", nil)
end
private_class_method :namespace
end
2 changes: 1 addition & 1 deletion app/lib/release_phase_notifier.rb
Expand Up @@ -8,7 +8,7 @@ def self.ping_slack
username: "Heroku",
)

client.ping("Release Phase Failed: #{ENV['FAILED_COMMAND']}")
client.ping("Release Phase Failed: #{ENV.fetch('FAILED_COMMAND', nil)}")
rescue Slack::Notifier::APIError => e
Honeybadger.notify(e)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/settings/smtp.rb
Expand Up @@ -40,7 +40,7 @@ def fallback_sendgrid_settings
port: 587,
authentication: :plain,
user_name: "apikey",
password: ENV["SENDGRID_API_KEY"],
password: ENV.fetch("SENDGRID_API_KEY", nil),
domain: ::Settings::General.app_domain
}
end
Expand Down
22 changes: 11 additions & 11 deletions app/models/users/deleted_user.rb
Expand Up @@ -12,17 +12,17 @@ module DeletedUser

# [@jeremyf] Yeah, this looks funny; it's analogue to `def.self
# method_name; nil; end`.
def self.deleted?() = true
def self.id() = nil
def self.darker_color() = Color::CompareHex.new(USER_COLORS).brightness
def self.username() = "[deleted user]"
def self.name() = I18n.t("models.users.deleted_user.name")
def self.summary() = nil
def self.twitter_username() = nil
def self.github_username() = nil
def self.profile_image_url() = nil
def self.path() = nil
def self.tag_line() = nil
def self.deleted? = true
def self.id = nil
def self.darker_color = Color::CompareHex.new(USER_COLORS).brightness
def self.username = "[deleted user]"
def self.name = I18n.t("models.users.deleted_user.name")
def self.summary = nil
def self.twitter_username = nil
def self.github_username = nil
def self.profile_image_url = nil
def self.path = nil
def self.tag_line = nil

# @return [String]
#
Expand Down
2 changes: 1 addition & 1 deletion app/services/mentions/create_all.rb
Expand Up @@ -24,7 +24,7 @@ def users_mentioned_in_text_excluding_author
mentioned_usernames = extract_usernames_from_mentions_in_text

collect_existing_users(mentioned_usernames)
.yield_self do |existing_mentioned_users|
.then do |existing_mentioned_users|
reject_notifiable_author(existing_mentioned_users)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/workers/push_notifications/cleanup_worker.rb
Expand Up @@ -5,7 +5,7 @@ class CleanupWorker
sidekiq_options queue: :low_priority, retry: 10, lock: :until_and_while_executing

def perform
redis = Redis.new(url: ENV["REDIS_RPUSH_URL"] || ENV["REDIS_URL"])
redis = Redis.new(url: ENV.fetch("REDIS_RPUSH_URL") { ENV.fetch("REDIS_URL", nil) })
cursor = 0
until (cursor, keys = redis.scan(cursor, match: "rpush:notifications:*")).first.to_i.zero?
keys.each do |key|
Expand Down
14 changes: 7 additions & 7 deletions config/environments/development.rb
Expand Up @@ -17,7 +17,7 @@
# Enable server timing
config.server_timing = true

config.cache_store = :redis_cache_store, { url: ENV["REDIS_URL"], expires_in: 1.hour.to_i }
config.cache_store = :redis_cache_store, { url: ENV.fetch("REDIS_URL", nil), expires_in: 1.hour.to_i }

# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
Expand Down Expand Up @@ -84,20 +84,20 @@
config.assets.raise_runtime_errors = true

config.hosts << ENV["APP_DOMAIN"] unless ENV["APP_DOMAIN"].nil?
if (gitpod_workspace_url = ENV["GITPOD_WORKSPACE_URL"])
if (gitpod_workspace_url = ENV.fetch("GITPOD_WORKSPACE_URL", nil))
config.hosts << /.*#{URI.parse(gitpod_workspace_url).host}/
end
config.app_domain = ENV["APP_DOMAIN"] || "localhost:3000"
config.app_domain = ENV.fetch("APP_DOMAIN", "localhost:3000")

config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { host: config.app_domain }
config.action_mailer.smtp_settings = {
address: ENV["SMTP_ADDRESS"],
port: ENV["SMTP_PORT"],
address: ENV.fetch("SMTP_ADDRESS", nil),
port: ENV.fetch("SMTP_PORT", nil),
authentication: ENV["SMTP_AUTHENTICATION"].presence || :plain,
user_name: ENV["SMTP_USER_NAME"],
password: ENV["SMTP_PASSWORD"],
user_name: ENV.fetch("SMTP_USER_NAME", nil),
password: ENV.fetch("SMTP_PASSWORD", nil),
domain: ENV["SMTP_DOMAIN"].presence || config.app_domain
}

Expand Down
14 changes: 7 additions & 7 deletions config/environments/production.rb
Expand Up @@ -53,7 +53,7 @@
config.assets.digest = true

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
config.action_controller.asset_host = ENV["FASTLY_CDN_URL"]
config.action_controller.asset_host = ENV.fetch("FASTLY_CDN_URL", nil)

# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
Expand All @@ -64,15 +64,15 @@

# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = ENV["LOG_LEVEL"] || :error
config.log_level = ENV.fetch("LOG_LEVEL", :error)

# Prepend all log lines with the following tags.
config.log_tags = [:request_id]

# Use a different cache store in production.
# DEV uses the RedisCloud Heroku Add-On which comes with the predefined env variable REDISCLOUD_URL
redis_url = ENV["REDISCLOUD_URL"]
redis_url ||= ENV["REDIS_URL"]
redis_url = ENV.fetch("REDISCLOUD_URL", nil)
redis_url ||= ENV.fetch("REDIS_URL", nil)
default_expiration = 24.hours.to_i
config.cache_store = :redis_cache_store, { url: redis_url, expires_in: default_expiration }

Expand Down Expand Up @@ -120,15 +120,15 @@
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

protocol = ENV["APP_PROTOCOL"] || "http://"
protocol = ENV.fetch("APP_PROTOCOL", "http://")

config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = false
config.action_mailer.default_url_options = { host: protocol + ENV["APP_DOMAIN"].to_s }

if ENV["HEROKU_APP_URL"].present? && ENV["HEROKU_APP_URL"] != ENV["APP_DOMAIN"]
config.middleware.use Rack::HostRedirect,
ENV["HEROKU_APP_URL"] => ENV["APP_DOMAIN"]
ENV.fetch("HEROKU_APP_URL", nil) => ENV.fetch("APP_DOMAIN", nil)
end

# Inserts middleware to perform automatic connection switching.
Expand All @@ -155,5 +155,5 @@
# rubocop:enable Metrics/BlockLength

Rails.application.routes.default_url_options = {
protocol: (ENV["APP_PROTOCOL"] || "http://").delete_suffix("://")
protocol: (ENV.fetch("APP_PROTOCOL", "http://")).delete_suffix("://")
}
2 changes: 1 addition & 1 deletion config/environments/test.rb
Expand Up @@ -7,7 +7,7 @@

# rubocop:disable Metrics/BlockLength
Rails.application.configure do
config.app_domain = ENV["APP_DOMAIN"] || "test.host"
config.app_domain = ENV.fetch("APP_DOMAIN", "test.host")

# Settings specified here will take precedence over those in config/application.rb.

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/flipper.rb
@@ -1,6 +1,6 @@
Flipper.configure do |config|
config.default do
adapter = if (cache_duration = ENV["CACHE_FEATURE_FLAGS_SECONDS"])
adapter = if (cache_duration = ENV.fetch("CACHE_FEATURE_FLAGS_SECONDS", nil))
Flipper::Adapters::ActiveSupportCacheStore.new(
Flipper::Adapters::ActiveRecord.new,
ActiveSupport::Cache::MemoryStore.new(expires_in: cache_duration.to_i.seconds),
Expand Down
6 changes: 3 additions & 3 deletions config/initializers/rpush.rb
Expand Up @@ -4,7 +4,7 @@
config.client = :redis

# Options passed to Redis.new
config.redis_options = { url: ENV["REDIS_RPUSH_URL"] || ENV["REDIS_URL"], driver: :ruby }
config.redis_options = { url: ENV.fetch("REDIS_RPUSH_URL") { ENV.fetch("REDIS_URL", nil) }, driver: :ruby }

# Frequency in seconds to check for new notifications.
config.push_poll = 2
Expand Down Expand Up @@ -59,7 +59,7 @@
tags: [
"app_bundle:#{notification.app&.bundle_id}",
"type:#{JSON.parse(notification.payload).dig('data', 'type') || 'unknown'}",
"host:#{ENV['APP_DOMAIN']}",
"host:#{ENV.fetch('APP_DOMAIN', nil)}",
],
)
end
Expand All @@ -82,7 +82,7 @@
"app_bundle:#{notification.app&.bundle_id}",
"error_code:#{notification.error_code}",
"error_description:#{notification.error_description}",
"host:#{ENV['APP_DOMAIN']}",
"host:#{ENV.fetch('APP_DOMAIN', nil)}",
],
)
end
Expand Down
6 changes: 3 additions & 3 deletions config/initializers/s3_direct_upload.rb
Expand Up @@ -8,9 +8,9 @@
ENV["AWS_S3_VIDEO_KEY"] = "available"
ENV["AWS_S3_INPUT_BUCKET"] = "available"
end
c.access_key_id = ENV["AWS_S3_VIDEO_ID"] # your access key id
c.secret_access_key = ENV["AWS_S3_VIDEO_KEY"] # your secret access key
c.bucket = ENV["AWS_S3_INPUT_BUCKET"] # your bucket name
c.access_key_id = ENV.fetch("AWS_S3_VIDEO_ID", nil) # your access key id
c.secret_access_key = ENV.fetch("AWS_S3_VIDEO_KEY", nil) # your secret access key
c.bucket = ENV.fetch("AWS_S3_INPUT_BUCKET", nil) # your bucket name
c.region = nil # region prefix. _Required_ for non-default AWS region, eg. "eu-west-1"
c.url = nil # S3 API endpoint (optional), eg. "https://#{c.bucket}.s3.amazonaws.com"
end
2 changes: 1 addition & 1 deletion config/initializers/sidekiq.rb
Expand Up @@ -11,7 +11,7 @@ def not_past_scheduled_time?(current_time)
# sidekiq workers, we need to ensure any job scheduled during that down time
# is run once Sidekiq boots back up
# https://github.com/ondrejbartas/sidekiq-cron/blob/074a87546f16122c1f508bb2805b9951588f2510/lib/sidekiq/cron/job.rb#L593
return false if (current_time.to_i - last_cron_time.to_i) > (ENV["CRON_LOOKBACK_TIME"] || 60).to_i
return false if (current_time.to_i - last_cron_time.to_i) > ENV.fetch("CRON_LOOKBACK_TIME", 60).to_i

true
end
Expand Down
6 changes: 3 additions & 3 deletions config/initializers/vault.rb
@@ -1,11 +1,11 @@
Vault.configure do |config|
# The address of the Vault server, also read as
config.address = ENV["VAULT_ADDR"] || "http://127.0.0.1:8200"
config.address = ENV.fetch("VAULT_ADDR", "http://127.0.0.1:8200")

# The policy token to authenticate with Vault
# Each app will get its own policy https://learn.hashicorp.com/vault/getting-started/policies#overview
# Each policy comes with its own token to give the app access to ONLY its secrets
config.token = ENV["VAULT_TOKEN"]
config.token = ENV.fetch("VAULT_TOKEN", nil)

# Mimic Paths for communities

Expand All @@ -26,7 +26,7 @@
# config.ssl_pem_contents = "-----BEGIN ENCRYPTED..."

# Use SSL verification, also read as ENV["VAULT_SSL_VERIFY"]
config.ssl_verify = ENV["VAULT_SSL_VERIFY"] || true
config.ssl_verify = ENV.fetch("VAULT_SSL_VERIFY", true)

# Timeout the connection after a certain amount of time (seconds), also read
# as ENV["VAULT_TIMEOUT"]
Expand Down
12 changes: 6 additions & 6 deletions lib/sitemap_generator/s3_adapter.rb
Expand Up @@ -5,12 +5,12 @@ module SitemapGenerator
# https://github.com/kjvarga/sitemap_generator/blob/master/lib/sitemap_generator/adapters/s3_adapter.rb
class S3Adapter
def initialize(opts = {}) # rubocop:disable Style/OptionHash
@aws_access_key_id = opts[:aws_access_key_id] || ENV["AWS_ACCESS_KEY_ID"]
@aws_secret_access_key = opts[:aws_secret_access_key] || ENV["AWS_SECRET_ACCESS_KEY"]
@fog_provider = opts[:fog_provider] || ENV["FOG_PROVIDER"]
@fog_directory = opts[:fog_directory] || ENV["FOG_DIRECTORY"]
@fog_region = opts[:fog_region] || ENV["FOG_REGION"]
@fog_path_style = opts[:fog_path_style] || ENV["FOG_PATH_STYLE"]
@aws_access_key_id = opts[:aws_access_key_id] || ENV.fetch("AWS_ACCESS_KEY_ID", nil)
@aws_secret_access_key = opts[:aws_secret_access_key] || ENV.fetch("AWS_SECRET_ACCESS_KEY", nil)
@fog_provider = opts[:fog_provider] || ENV.fetch("FOG_PROVIDER", nil)
@fog_directory = opts[:fog_directory] || ENV.fetch("FOG_DIRECTORY", nil)
@fog_region = opts[:fog_region] || ENV.fetch("FOG_REGION", nil)
@fog_path_style = opts[:fog_path_style] || ENV.fetch("FOG_PATH_STYLE", nil)
@fog_storage_options = opts[:fog_storage_options] || {}
@fog_public = opts[:fog_public].to_s.present? ? opts[:fog_public] : true # additional line
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/data_updates.rake
Expand Up @@ -12,7 +12,7 @@ namespace :data_updates do

# Use the env variable to delay running data update scripts if your
# deploy strategy requires it
DataUpdateWorker.perform_in(ENV["WORKERS_DATA_UPDATE_DELAY_SECONDS"] || default_delay)
DataUpdateWorker.perform_in(ENV.fetch("WORKERS_DATA_UPDATE_DELAY_SECONDS") { default_delay })
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/release_phase_notifier_spec.rb
Expand Up @@ -11,7 +11,7 @@
it "sends a failure message to slack" do
allow(ENV).to receive(:[]).with("FAILED_COMMAND").and_return("rake db:migrate")
mock_slack = Slack::Notifier.new("url")
failure_message = "Release Phase Failed: #{ENV['FAILED_COMMAND']}"
failure_message = "Release Phase Failed: #{ENV.fetch('FAILED_COMMAND', nil)}"
allow(Slack::Notifier).to receive(:new) { mock_slack }
allow(mock_slack).to receive(:ping)

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/url_spec.rb
Expand Up @@ -99,7 +99,7 @@
it "returns the correct URL for a tag with a non-ASCII name" do
# Due to validations we can't trivially create a tag with a non-ASCII name
# so we just create something that quacks like one.
tag = instance_double("Tag", name: "histórico")
tag = instance_double(Tag, name: "histórico")
expect(described_class.tag(tag)).to eq("https://dev.to/t/hist%C3%B3rico")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/liquid_tags/medium_tag_spec.rb
Expand Up @@ -5,7 +5,7 @@

before { Liquid::Template.register_tag("medium", described_class) }

let(:stubbed_scraper) { instance_double("MediumArticleRetrievalService") }
let(:stubbed_scraper) { instance_double(MediumArticleRetrievalService) }
let(:medium_link) { "https://medium.com/@edisonywh/my-ruby-journey-hooking-things-up-91d757e1c59c" }
let(:response) do
{
Expand Down
2 changes: 1 addition & 1 deletion spec/models/admin_menu_spec.rb
Expand Up @@ -4,7 +4,7 @@
describe ".nested_menu_items_from_request" do
subject(:method_call) { described_class.nested_menu_items_from_request(request) }

let(:request) { instance_double("ActionDispatch::Request", path: path) }
let(:request) { instance_double(ActionDispatch::Request, path: path) }
let(:path) { "/admin" }

context "when path is /admin/moderation/feedback_messages" do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/forem_instance_spec.rb
Expand Up @@ -19,7 +19,7 @@
it "sets the HEROKU_RELEASE_CREATED_AT if the RELEASE_FOOTPRINT is not present" do
allow(ApplicationConfig).to receive(:[]).with("RELEASE_FOOTPRINT").and_return("")
allow(ENV).to receive(:[]).with("HEROKU_RELEASE_CREATED_AT").and_return("A deploy date set on Heroku")
expect(described_class.deployed_at).to eq(ENV["HEROKU_RELEASE_CREATED_AT"])
expect(described_class.deployed_at).to eq("A deploy date set on Heroku")
end

it "sets to current time if HEROKU_RELEASE_CREATED_AT and RELEASE_FOOTPRINT are not present" do
Expand All @@ -45,7 +45,7 @@
it "sets the HEROKU_RELEASE_CREATED_AT if the RELEASE_FOOTPRINT is not present" do
allow(ApplicationConfig).to receive(:[]).with("FOREM_BUILD_SHA").and_return("")
stub_const("ENV", ENV.to_h.merge("HEROKU_SLUG_COMMIT" => "A Commit ID set from Heroku"))
expect(described_class.latest_commit_id).to eq(ENV["HEROKU_SLUG_COMMIT"])
expect(described_class.latest_commit_id).to eq(ENV.fetch("HEROKU_SLUG_COMMIT", nil))
end
end

Expand Down