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

Naming/BlockForwarding with -a creates syntax error #12807

Closed
NathanZookCH opened this issue Mar 22, 2024 · 0 comments · Fixed by #12808
Closed

Naming/BlockForwarding with -a creates syntax error #12807

NathanZookCH opened this issue Mar 22, 2024 · 0 comments · Fixed by #12808
Labels

Comments

@NathanZookCH
Copy link

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
@koic koic added the bug label Mar 22, 2024
koic added a commit to koic/rubocop that referenced this issue Mar 22, 2024
Fixes rubocop#12807.

This PR fixes false positives for `Naming/BlockForwarding`
when using explicit block forwarding in block method and others.
koic added a commit to koic/rubocop that referenced this issue Mar 22, 2024
Fixes rubocop#12807.

This PR fixes false positives for `Naming/BlockForwarding`
when using explicit block forwarding in block method and others.
koic added a commit to koic/rubocop that referenced this issue Mar 22, 2024
Fixes rubocop#12807.

This PR fixes false positives for `Naming/BlockForwarding`
when using explicit block forwarding in block method and others.
koic added a commit to koic/rubocop that referenced this issue Mar 22, 2024
Fixes rubocop#12807.

This PR fixes false positives for `Naming/BlockForwarding`
when using explicit block forwarding in block method and others.
koic added a commit that referenced this issue Mar 23, 2024
…ock_forwarding

[Fix #12807] Fix false positives for `Naming/BlockForwarding`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants