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

Invalid autocorrection behavior for Style/CombinableLoops and Lint/UnusedBlockArgument cops #12322

Closed
ydakuka opened this issue Oct 28, 2023 · 0 comments · Fixed by #12329
Closed
Labels

Comments

@ydakuka
Copy link

ydakuka commented Oct 28, 2023

Actual behavior

I have the code:

class Test
  def my_method
    # bad - easier to move/add/remove parameters, but still not preferred
    [[1, 2, 3], [4, 5, 6]].each do |a, b, c,|
      a + b + c
    end

    # good
    [[1, 2, 3], [4, 5, 6]].each do |a, b, c|
      a + b + c
    end

    # bad
    [[1, 2, 3], [4, 5, 6]].each { |a, b, c,| a + b + c }
  end
end

If I run rubocop with -A option, I will get:

ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop -A app/models/test_class.rb
Inspecting 1 file
An error occurred while Style/CombinableLoops cop was inspecting /app/app/models/test_class.rb:16:4.
To see the complete backtrace run rubocop -d.
W

Offenses:

app/models/test_class.rb:6:5: W: Lint/EmptyBlock: Empty block detected.
    [[1, 2, 3], [4, 5, 6]].each do |a, b, _c,| ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/test_class.rb:6:43: W: [Corrected] Lint/UnusedBlockArgument: Unused block argument - c. If it's necessary, use _ or _c as an argument name to indicate that it won't be used.
    [[1, 2, 3], [4, 5, 6]].each do |a, b, c,|
                                          ^
app/models/test_class.rb:7:7: W: [Corrected] Lint/Void: Variable a used in void context.
      a
      ^
app/models/test_class.rb:7:9: W: [Corrected] Lint/Void: Operator + used in void context.
      a + b
        ^
app/models/test_class.rb:7:13: W: [Corrected] Lint/Void: Operator + used in void context.
      a + b + c
            ^
app/models/test_class.rb:8:1: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
a + b + c
^^^^^^^^^
app/models/test_class.rb:8:1: W: [Corrected] Lint/Void: Variable b used in void context.
b
^
app/models/test_class.rb:8:1: W: [Corrected] Lint/Void: Variable c used in void context.
c
^
app/models/test_class.rb:8:7: W: [Corrected] Lint/Void: Operator + used in void context.
a + b + c
      ^
app/models/test_class.rb:8:7: W: [Corrected] Lint/Void: Variable b used in void context.
      b
      ^
app/models/test_class.rb:8:7: W: [Corrected] Lint/Void: Variable c used in void context.
      c
      ^
app/models/test_class.rb:9:7: W: [Corrected] Lint/Void: Variable a used in void context.
      a
      ^
app/models/test_class.rb:9:9: W: [Corrected] Lint/Void: Operator + used in void context.
      a + b
        ^
app/models/test_class.rb:10:1: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
c
^
app/models/test_class.rb:10:1: W: [Corrected] Lint/Void: Variable b used in void context.
b
^
app/models/test_class.rb:10:1: W: [Corrected] Lint/Void: Variable c used in void context.
c
^
app/models/test_class.rb:10:7: W: [Corrected] Lint/Void: Variable b used in void context.
      b
      ^
app/models/test_class.rb:10:7: W: [Corrected] Lint/Void: Variable c used in void context.
      c
      ^
app/models/test_class.rb:11:5: C: [Corrected] Style/CombinableLoops: Combine this loop with the previous loop.
    [[1, 2, 3], [4, 5, 6]].each do |a, b, c| ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/test_class.rb:14:5: C: [Corrected] Style/CombinableLoops: Combine this loop with the previous loop.
    [[1, 2, 3], [4, 5, 6]].each { |a, b, c,| a + b + c }
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/test_class.rb:16:5: C: [Corrected] Style/CombinableLoops: Combine this loop with the previous loop.
    [[1, 2, 3], [4, 5, 6]].each { |a, b, c,| a + b + c }
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 21 offenses detected, 20 offenses corrected

1 error occurred:
An error occurred while Style/CombinableLoops cop was inspecting /app/app/models/test_class.rb:16:4.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.57.2 (using Parser 3.2.2.4, rubocop-ast 1.29.0, running on ruby 2.7.8) [x86_64-linux]

Rubocop

ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop -V
1.57.2 (using Parser 3.2.2.4, rubocop-ast 1.29.0, running on ruby 2.7.8) [x86_64-linux]
  - rubocop-capybara 2.19.0
  - rubocop-factory_bot 2.24.0
  - rubocop-performance 1.19.1
  - rubocop-rails 2.22.0
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.25.0
  - rubocop-thread_safety 0.5.1
@ydakuka ydakuka changed the title Invalid autocorrection behavior for Style/CombinableLoops cop Invalid autocorrection behavior for Style/CombinableLoops cop Oct 28, 2023
@ydakuka ydakuka changed the title Invalid autocorrection behavior for Style/CombinableLoops cop Invalid autocorrection behavior for Style/CombinableLoops and Lint/UnusedBlockArgument cops Oct 28, 2023
@koic koic added the bug label Nov 1, 2023
koic added a commit to koic/rubocop that referenced this issue Nov 1, 2023
Fixes rubocop#12322.

This PR fixes an error for `Style/CombinableLoops`
when looping over the same data for the third consecutive time or more.
koic added a commit that referenced this issue Nov 1, 2023
[Fix #12322] Fix an error for `Style/CombinableLoops`
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