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

Percent array literal inside a block causes infinite loop with --disable-uncorrectable. #12208

Closed
sliiser opened this issue Sep 20, 2023 · 0 comments · Fixed by #12220
Closed
Labels

Comments

@sliiser
Copy link

sliiser commented Sep 20, 2023

A rather simple example that causes an infinite loop with several cops. The example is given with Metrics/MethodLength, but is also reproducible with Metrics/ClassLength, Metrics/AbcSize, Metrics/CyclomaticComplexity and Metrics/PerceivedComplexity. List is not exhaustive.


Steps to reproduce the problem

# .rubocop.yml
AllCops:
  NewCops: enable

Metrics/MethodLength:
  Max: 2 # just for demonstration
# frozen_string_literal: true

def foo
  bar do
    %w[]
  end
end

$ rubocop -A --disable-uncorrectable

Expected behavior

# frozen_string_literal: true

def foo # rubocop:todo Metrics/MethodLength
  bar do
    %w[]
  end
end

Actual behavior

# frozen_string_literal: true

def foo
  bar do
    # rubocop:todo Metrics/MethodLength
    # rubocop:todo Metrics/MethodLength
    # rubocop:todo Metrics/MethodLength
    ...
    # rubocop:todo Metrics/MethodLength
    # rubocop:todo Metrics/MethodLength
    # rubocop:todo Metrics/MethodLength
    %w[]
    # rubocop:enable Metrics/MethodLength
    # rubocop:enable Metrics/MethodLength
    # rubocop:enable Metrics/MethodLength
    ...
    # rubocop:enable Metrics/MethodLength
    # rubocop:enable Metrics/MethodLength
    # rubocop:enable Metrics/MethodLength
  end
end

Infinite loop detected in <the file>.rb and caused by Metrics/MethodLength

RuboCop version

$ rubocop -V
1.56.3 (using Parser 3.2.2.3, rubocop-ast 1.28.1, running on ruby 3.2.2) [arm64-darwin22]
$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
@sliiser sliiser changed the title Percent array literal inside a block causes infinite loop. Percent array literal inside a block causes infinite loop with --disable-uncorrectable. Sep 20, 2023
@koic koic added the bug label Sep 20, 2023
koic added a commit to koic/rubocop that referenced this issue Sep 26, 2023
…ncorrectable` option

Fixes rubocop#12208.

This PR fixes an incorrect autocorrect for the `--disable-uncorrectable` command line option
when registering an offense is outside a percent array.
koic added a commit that referenced this issue Sep 26, 2023
…disable_uncorrectable_option

[Fix #12208] Fix an incorrect autocorrect for the `--disable-uncorrectable` option
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