Add and apply Naming/BlockForwarding rubocop rule
This syntax has been added in Ruby 3.1. Not using a variable name might not be very descriptive, but it's just as descriptive as using "block" as a variable name. Using just `&` we get the same amount of information than using `&block`: that we're passing a block. We're still using `&action` in `around_action` methods because here we aren't using a generic name for the variable, so (at least for now) we aren't running this cop on controllers using `around_action`.
This commit is contained in:
@@ -319,6 +319,13 @@ Lint/UselessAssignment:
|
|||||||
Lint/Void:
|
Lint/Void:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
Naming/BlockForwarding:
|
||||||
|
Enabled: true
|
||||||
|
Exclude:
|
||||||
|
- "app/controllers/application_controller.rb"
|
||||||
|
- "app/controllers/management/base_controller.rb"
|
||||||
|
- "app/controllers/subscriptions_controller.rb"
|
||||||
|
|
||||||
Naming/VariableName:
|
Naming/VariableName:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class StatsController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def daily_cache(key, &block)
|
def daily_cache(key, &)
|
||||||
Rails.cache.fetch("public_stats/#{Time.current.strftime("%Y-%m-%d")}/#{key}", &block)
|
Rails.cache.fetch("public_stats/#{Time.current.strftime("%Y-%m-%d")}/#{key}", &)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module Types
|
module Types
|
||||||
class BaseObject < GraphQL::Schema::Object
|
class BaseObject < GraphQL::Schema::Object
|
||||||
def self.field(*args, **kwargs, &block)
|
def self.field(*args, **kwargs, &)
|
||||||
super(*args, **kwargs, &block)
|
super(*args, **kwargs, &)
|
||||||
|
|
||||||
# The old api contained non-camelized fields
|
# The old api contained non-camelized fields
|
||||||
# We want to support these for now, but throw a deprecation warning
|
# We want to support these for now, but throw a deprecation warning
|
||||||
@@ -14,7 +14,7 @@ module Types
|
|||||||
if field_name.to_s.include?("_")
|
if field_name.to_s.include?("_")
|
||||||
reason = "Snake case fields are deprecated. Please use #{field_name.to_s.camelize(:lower)}."
|
reason = "Snake case fields are deprecated. Please use #{field_name.to_s.camelize(:lower)}."
|
||||||
kwargs = kwargs.merge({ camelize: false, deprecation_reason: reason })
|
kwargs = kwargs.merge({ camelize: false, deprecation_reason: reason })
|
||||||
super(*args, **kwargs, &block)
|
super(*args, **kwargs, &)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Make sure associations only return public records
|
# Make sure associations only return public records
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ module GlobalizeHelper
|
|||||||
hidden_field_tag("enabled_translations[#{locale}]", (enabled ? 1 : 0))
|
hidden_field_tag("enabled_translations[#{locale}]", (enabled ? 1 : 0))
|
||||||
end
|
end
|
||||||
|
|
||||||
def globalize(locale, &block)
|
def globalize(locale, &)
|
||||||
Globalize.with_locale(locale, &block)
|
Globalize.with_locale(locale, &)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module TranslatableFormHelper
|
module TranslatableFormHelper
|
||||||
def translatable_form_for(record, options = {}, &block)
|
def translatable_form_for(record, options = {}, &)
|
||||||
form_for(record, options.merge(builder: TranslatableFormBuilder), &block)
|
form_for(record, options.merge(builder: TranslatableFormBuilder), &)
|
||||||
end
|
end
|
||||||
|
|
||||||
def translations_interface_enabled?
|
def translations_interface_enabled?
|
||||||
@@ -18,13 +18,13 @@ module TranslatableFormHelper
|
|||||||
class TranslatableFormBuilder < ConsulFormBuilder
|
class TranslatableFormBuilder < ConsulFormBuilder
|
||||||
attr_accessor :translations
|
attr_accessor :translations
|
||||||
|
|
||||||
def translatable_fields(&block)
|
def translatable_fields(&)
|
||||||
@translations = {}
|
@translations = {}
|
||||||
visible_locales.map do |locale|
|
visible_locales.map do |locale|
|
||||||
@translations[locale] = translation_for(locale)
|
@translations[locale] = translation_for(locale)
|
||||||
end
|
end
|
||||||
safe_join(visible_locales.map do |locale|
|
safe_join(visible_locales.map do |locale|
|
||||||
Globalize.with_locale(locale) { fields_for_locale(locale, &block) }
|
Globalize.with_locale(locale) { fields_for_locale(locale, &) }
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -46,8 +46,8 @@ module TranslatableFormHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fields_for_translation(translation, &block)
|
def fields_for_translation(translation, &)
|
||||||
fields_for(:translations, translation, builder: TranslationsFieldsBuilder, &block)
|
fields_for(:translations, translation, builder: TranslationsFieldsBuilder, &)
|
||||||
end
|
end
|
||||||
|
|
||||||
def translation_for(locale)
|
def translation_for(locale)
|
||||||
|
|||||||
@@ -158,8 +158,8 @@ class Mailer < ApplicationMailer
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def with_user(user, &block)
|
def with_user(user, &)
|
||||||
I18n.with_locale(user.locale, &block)
|
I18n.with_locale(user.locale, &)
|
||||||
end
|
end
|
||||||
|
|
||||||
def prevent_delivery_to_users_without_email
|
def prevent_delivery_to_users_without_email
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ class Budget::Stats
|
|||||||
|
|
||||||
stats_cache(*stats_methods)
|
stats_cache(*stats_methods)
|
||||||
|
|
||||||
def stats_cache(key, &block)
|
def stats_cache(key, &)
|
||||||
Rails.cache.fetch("budgets_stats/#{budget.id}/#{phases.join}/#{key}/#{version}", &block)
|
Rails.cache.fetch("budgets_stats/#{budget.id}/#{phases.join}/#{key}/#{version}", &)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class Poll::Stats
|
|||||||
|
|
||||||
stats_cache(*stats_methods)
|
stats_cache(*stats_methods)
|
||||||
|
|
||||||
def stats_cache(key, &block)
|
def stats_cache(key, &)
|
||||||
Rails.cache.fetch("polls_stats/#{poll.id}/#{key}/#{version}", &block)
|
Rails.cache.fetch("polls_stats/#{poll.id}/#{key}/#{version}", &)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -139,9 +139,9 @@ class Tenant < ApplicationRecord
|
|||||||
Apartment::Tenant.switch(...)
|
Apartment::Tenant.switch(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.run_on_each(&block)
|
def self.run_on_each(&)
|
||||||
["public"].union(Apartment.tenant_names).each do |schema|
|
["public"].union(Apartment.tenant_names).each do |schema|
|
||||||
switch(schema, &block)
|
switch(schema, &)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class RemoteTranslations::Microsoft::AvailableLocales
|
|||||||
JSON.parse(result)["translation"].map(&:first)
|
JSON.parse(result)["translation"].map(&:first)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.daily_cache(key, &block)
|
def self.daily_cache(key, &)
|
||||||
Rails.cache.fetch("remote_available_locales/#{Time.current.strftime("%Y-%m-%d")}/#{key}", &block)
|
Rails.cache.fetch("remote_available_locales/#{Time.current.strftime("%Y-%m-%d")}/#{key}", &)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
def in_browser(name, &block)
|
def in_browser(name, &)
|
||||||
Capybara.using_session(name, &block)
|
Capybara.using_session(name, &)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user