Exclude each_batch from rubocop rule for Style/SymbolProc
Problem
As noticed in !137887 (comment 1675424713).
When using each_batch
, rubocop's Style/SymbolProc
rule wants to avoid using a block if the batch just calls a method that can be written as a symbol proc. For example, the following code
records.each_batch(of: BATCH_SIZE) do |records_batch|
records_batch.delete_all
end
returns this rubocop offense
Style/SymbolProc: Pass &:delete_all as an argument to each_batch instead of a block.
When following the suggestion and change the code to
records.each_batch(of: BATCH_SIZE, &:delete_all)
# or
records.each_batch(of: BATCH_SIZE)&.map(&:delete_all)
the code started to break with
ArgumentError:
wrong number of arguments (given 1, expected 0)
# or
LocalJumpError:
no block given (yield)
Proposal
While there are multiple places ((here, here, and here plus more)) where the rubocop rule for Style/SymbolProc
was disabled inline, it makes more sense to exclude each_batch
from it in general to avoid having to disable it each time inline.
Additionally, re-add already defined methods (define_method
, mail
, and respond_to
) to the rule config (also see !137887 (comment 1677975669)).
Places where the rule has been disabled should get cleaned up as part of this issue.