Naming/BlockForwarding with -a creates syntax error
NathanZookCH opened this issue · comments
Nathan Zook commented
Rubocop -a breaks the following code:
def each(&block)
results.each { |result| yield_objects(result, &block) }
append_results(&block) while results.last.next_page?
end
Expected behavior
Code should be left unchanged
Actual behavior
<CONFIG READ STATEMENTS DROPPED>
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
rubocop -a --debug result.rb
Inspecting 1 file
F
Offenses:
result.rb:41:24: F: Lint/Syntax: no anonymous block parameter
(Using Ruby 3.2 parser; configure using TargetRubyVersion parameter, under AllCops)
append_results(&) while results.last.next_page?
^
result.rb:41:24: C: [Corrected] Naming/BlockForwarding: Use anonymous block forwarding.
append_results(&block) while results.last.next_page?
^^^^^^
1 file inspected, 2 offenses detected, 1 offense corrected
.rubocop.yml:
require:
- rubocop-rspec
AllCops:
TargetRubyVersion: 3.2.0
NewCops: enable
Exclude:
- '**/*.rake'
- 'bin/*'
- 'db/**/*.rb'
# - 'lib/**/*.rb'
- 'Rakefile'
# - 'spec/**/*.rb'
- 'vendor/**/*'
Layout:
Metrics/LineLength:
Max: 120
Style/FrozenStringLiteralComment:
Enabled: false
Style/Documentation:
Enabled: false
Naming/HeredocDelimiterNaming:
Enabled: false
And the file is changed to
def each(&block)
results.each { |result| yield_objects(result, &block) }
append_results(&) while results.last.next_page?
end
Attempting to load the file results in a syntax error:
(irb):1:in `load': --> result.rb
no anonymous block parameter
8 class Result
39 def each(&block)
> 40 results.each { |result| yield_objects(result, &block) }
> 41 append_results(&) while results.last.next_page?
42 end
52 end
result.rb:41: no anonymous block parameter (SyntaxError)
Steps to reproduce the problem
rubocop -a result.rb
irb
001 > load 'result.rb'
RuboCop version
rubocop -V
1.60.2 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 3.2.2) [x86_64-darwin21]
- rubocop-rspec 2.27.1