Skip to content

Commit 78e4020

Browse files
authored
Merge pull request rails#43170 from byroot/rubocop-explicit-block-argument
Enable `Style/ExplicitBlockArgument` cop
2 parents 5fbc750 + c91c266 commit 78e4020

File tree

56 files changed

+188
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+188
-267
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ Style/DefWithParentheses:
143143
Style/MethodDefParentheses:
144144
Enabled: true
145145

146+
Style/ExplicitBlockArgument:
147+
Enabled: true
148+
146149
Style/FrozenStringLiteralComment:
147150
Enabled: true
148151
EnforcedStyle: always

actioncable/lib/action_cable/connection/tagged_logger_proxy.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def add_tags(*tags)
1818
@tags = @tags.uniq
1919
end
2020

21-
def tag(logger)
21+
def tag(logger, &block)
2222
if logger.respond_to?(:tagged)
2323
current_tags = tags - logger.formatter.current_tags
24-
logger.tagged(*current_tags) { yield }
24+
logger.tagged(*current_tags, &block)
2525
else
2626
yield
2727
end

actioncable/lib/action_cable/server/worker.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ def stopping?
3636
@executor.shuttingdown?
3737
end
3838

39-
def work(connection)
39+
def work(connection, &block)
4040
self.connection = connection
4141

42-
run_callbacks :work do
43-
yield
44-
end
42+
run_callbacks :work, &block
4543
ensure
4644
self.connection = nil
4745
end

actioncable/lib/action_cable/server/worker/active_record_connection_management.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ module ActiveRecordConnectionManagement
1212
end
1313
end
1414

15-
def with_database_connections
16-
connection.logger.tag(ActiveRecord::Base.logger) { yield }
15+
def with_database_connections(&block)
16+
connection.logger.tag(ActiveRecord::Base.logger, &block)
1717
end
1818
end
1919
end

actionpack/lib/abstract_controller/caching/fragments.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ def expire_fragment(key, options = nil)
142142
end
143143
end
144144

145-
def instrument_fragment_cache(name, key) # :nodoc:
146-
ActiveSupport::Notifications.instrument("#{name}.#{instrument_name}", instrument_payload(key)) { yield }
145+
def instrument_fragment_cache(name, key, &block) # :nodoc:
146+
ActiveSupport::Notifications.instrument("#{name}.#{instrument_name}", instrument_payload(key), &block)
147147
end
148148
end
149149
end

actionpack/lib/action_controller/metal/strong_parameters.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ def convert_value_to_parameters(value)
940940
def each_element(object, &block)
941941
case object
942942
when Array
943-
object.grep(Parameters).filter_map { |el| yield el }
943+
object.grep(Parameters).filter_map(&block)
944944
when Parameters
945945
if object.nested_attributes?
946946
object.each_nested_attribute(&block)

actionpack/lib/action_dispatch/http/mime_type.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def initialize
1313
@symbols = []
1414
end
1515

16-
def each
17-
@mimes.each { |x| yield x }
16+
def each(&block)
17+
@mimes.each(&block)
1818
end
1919

2020
def <<(type)
@@ -42,9 +42,9 @@ def [](type)
4242
Type.lookup_by_extension(type)
4343
end
4444

45-
def fetch(type)
45+
def fetch(type, &block)
4646
return type if type.is_a?(Type)
47-
EXTENSION_LOOKUP.fetch(type.to_s) { |k| yield k }
47+
EXTENSION_LOOKUP.fetch(type.to_s, &block)
4848
end
4949
end
5050

actionpack/lib/action_dispatch/middleware/stack.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def initialize(*args)
8383
yield(self) if block_given?
8484
end
8585

86-
def each
87-
@middlewares.each { |x| yield x }
86+
def each(&block)
87+
@middlewares.each(&block)
8888
end
8989

9090
def size

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ def controller(controller)
922922
# namespace :admin, as: "sekret" do
923923
# resources :posts
924924
# end
925-
def namespace(path, options = {})
925+
def namespace(path, options = {}, &block)
926926
path = path.to_s
927927

928928
defaults = {
@@ -933,7 +933,7 @@ def namespace(path, options = {})
933933
}
934934

935935
path_scope(options.delete(:path) { path }) do
936-
scope(defaults.merge!(options)) { yield }
936+
scope(defaults.merge!(options), &block)
937937
end
938938
end
939939

@@ -992,8 +992,8 @@ def namespace(path, options = {})
992992
# constraints(Iphone) do
993993
# resources :iphones
994994
# end
995-
def constraints(constraints = {})
996-
scope(constraints: constraints) { yield }
995+
def constraints(constraints = {}, &block)
996+
scope(constraints: constraints, &block)
997997
end
998998

999999
# Allows you to set default parameters for a route, such as this:
@@ -1493,15 +1493,13 @@ def resources(*resources, &block)
14931493
# with GET, and route to the search action of +PhotosController+. It will also
14941494
# create the <tt>search_photos_url</tt> and <tt>search_photos_path</tt>
14951495
# route helpers.
1496-
def collection
1496+
def collection(&block)
14971497
unless resource_scope?
14981498
raise ArgumentError, "can't use collection outside resource(s) scope"
14991499
end
15001500

15011501
with_scope_level(:collection) do
1502-
path_scope(parent_resource.collection_scope) do
1503-
yield
1504-
end
1502+
path_scope(parent_resource.collection_scope, &block)
15051503
end
15061504
end
15071505

@@ -1516,35 +1514,33 @@ def collection
15161514
# This will recognize <tt>/photos/1/preview</tt> with GET, and route to the
15171515
# preview action of +PhotosController+. It will also create the
15181516
# <tt>preview_photo_url</tt> and <tt>preview_photo_path</tt> helpers.
1519-
def member
1517+
def member(&block)
15201518
unless resource_scope?
15211519
raise ArgumentError, "can't use member outside resource(s) scope"
15221520
end
15231521

15241522
with_scope_level(:member) do
15251523
if shallow?
15261524
shallow_scope {
1527-
path_scope(parent_resource.member_scope) { yield }
1525+
path_scope(parent_resource.member_scope, &block)
15281526
}
15291527
else
1530-
path_scope(parent_resource.member_scope) { yield }
1528+
path_scope(parent_resource.member_scope, &block)
15311529
end
15321530
end
15331531
end
15341532

1535-
def new
1533+
def new(&block)
15361534
unless resource_scope?
15371535
raise ArgumentError, "can't use new outside resource(s) scope"
15381536
end
15391537

15401538
with_scope_level(:new) do
1541-
path_scope(parent_resource.new_scope(action_path(:new))) do
1542-
yield
1543-
end
1539+
path_scope(parent_resource.new_scope(action_path(:new)), &block)
15441540
end
15451541
end
15461542

1547-
def nested
1543+
def nested(&block)
15481544
unless resource_scope?
15491545
raise ArgumentError, "can't use nested outside resource(s) scope"
15501546
end
@@ -1553,12 +1549,12 @@ def nested
15531549
if shallow? && shallow_nesting_depth >= 1
15541550
shallow_scope do
15551551
path_scope(parent_resource.nested_scope) do
1556-
scope(nested_options) { yield }
1552+
scope(nested_options, &block)
15571553
end
15581554
end
15591555
else
15601556
path_scope(parent_resource.nested_scope) do
1561-
scope(nested_options) { yield }
1557+
scope(nested_options, &block)
15621558
end
15631559
end
15641560
end
@@ -1744,10 +1740,10 @@ def with_scope_level(kind) # :doc:
17441740
@scope = @scope.parent
17451741
end
17461742

1747-
def resource_scope(resource)
1743+
def resource_scope(resource, &block)
17481744
@scope = @scope.new(scope_level_resource: resource)
17491745

1750-
controller(resource.resource_scope) { yield }
1746+
controller(resource.resource_scope, &block)
17511747
ensure
17521748
@scope = @scope.parent
17531749
end

actionpack/lib/action_dispatch/routing/route_set.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def key?(name)
131131
alias [] get
132132
alias clear clear!
133133

134-
def each
135-
routes.each { |name, route| yield name, route }
134+
def each(&block)
135+
routes.each(&block)
136136
self
137137
end
138138

0 commit comments

Comments
 (0)