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

Infinite loop with Style/IfUnlessModifier -> Layout/EndAlignment, Layout/IndentationWidth #12754

Open
alagos opened this issue Mar 6, 2024 · 0 comments
Labels

Comments

@alagos
Copy link

alagos commented Mar 6, 2024

I have this method:

def previous_or_next_page(page, text, classname)
  tag :li, link(text, page || '#'), class: [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page)].join(' ')
end

Expected behavior

Format it to something like:

def previous_or_next_page(page, text, classname)
  tag :li, link(text, page || '#'),
      class: [(classname[0..3] if @options[:page_links]),
              (classname if @options[:page_links]),
              ('disabled' unless page)].join(' ')
end

Actual behavior

The code is changed to

def previous_or_next_page(page, text, classname)
  tag :li, link(text, page || '#'),
      class: [(if @options[:page_links]
                 classname[0..3]
               end), (if @options[:page_links]
                        classname
                      end), (unless page
                               'disabled'
                             end)].join(' ')
end

and I get an "Infinite loop detected" error at the end.

❯ rubocop -a --debug /Users/alter/test.rb
For /Users/alter: Default configuration from /Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /Users/alter/test.rb
W

Offenses:

test.rb:2:36: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
  tag :li, link(text, page || '#'),
                                   ^
test.rb:2:62: C: [Corrected] Style/IfUnlessModifier: Modifier form of if makes the line too long.
  tag :li, link(text, page || '#'), class: [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page)].join(' ')
                                                             ^^
test.rb:2:100: C: [Corrected] Style/IfUnlessModifier: Modifier form of if makes the line too long.
  tag :li, link(text, page || '#'), class: [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page)].join(' ')
                                                                                                   ^^
test.rb:2:121: C: [Corrected] Layout/LineLength: Line is too long. [161/120]
  tag :li, link(text, page || '#'), class: [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page)].join(' ')
                                                                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:2:139: C: [Corrected] Style/IfUnlessModifier: Modifier form of unless makes the line too long.
  tag :li, link(text, page || '#'), class: [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page)].join(' ')
                                                                                                                                          ^^^^^^
test.rb:3:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
class: [(if @options[:page_links] ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:3:10: C: [Corrected] Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
class: [(if @options[:page_links]
         ^^
test.rb:3:16: C: [Corrected] Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
      class: [(if @options[:page_links]
               ^^
test.rb:3:32: C: [Corrected] Style/IfUnlessModifier: Modifier form of if makes the line too long.
      class: [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page)].join(' ')
                               ^^
test.rb:3:70: C: [Corrected] Style/IfUnlessModifier: Modifier form of if makes the line too long.
      class: [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page)].join(' ')
                                                                     ^^
test.rb:3:109: C: [Corrected] Style/IfUnlessModifier: Modifier form of unless makes the line too long.
      class: [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page)].join(' ')
                                                                                                            ^^^^^^
test.rb:4:10: C: [Corrected] Layout/IndentationWidth: Use 2 (not 38) spaces for indentation.
                                               classname[0..3]
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:5:23: C: [Corrected] Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
               end), (if @options[:page_links]
                      ^^
test.rb:5:46: W: [Corrected] Layout/EndAlignment: end at 5, 45 is not aligned with if at 3, 9.
                                             end), (if @options[:page_links]
                                             ^^^
test.rb:5:53: C: [Corrected] Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
                                             end), (if @options[:page_links]
                                                    ^^
test.rb:6:23: C: [Corrected] Layout/IndentationWidth: Use 2 (not 38) spaces for indentation.
                                                            classname
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:6:23: C: [Corrected] Layout/IndentationWidth: Use 2 (not 39) spaces for indentation.
                                                             classname
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:6:53: C: [Corrected] Layout/IndentationWidth: Use 2 (not 39) spaces for indentation.
                                                                                           classname
                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:7:30: C: [Corrected] Style/IfUnlessModifier: Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
                      end), (unless page
                             ^^^^^^
test.rb:7:59: W: [Corrected] Layout/EndAlignment: end at 7, 58 is not aligned with if at 5, 22.
                                                          end), (unless page
                                                          ^^^
test.rb:7:60: W: [Corrected] Layout/EndAlignment: end at 7, 59 is not aligned with if at 5, 22.
                                                           end), (unless page
                                                           ^^^
test.rb:7:66: C: [Corrected] Style/IfUnlessModifier: Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
                                                          end), (unless page
                                                                 ^^^^^^
test.rb:7:67: C: [Corrected] Style/IfUnlessModifier: Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
                                                           end), (unless page
                                                                  ^^^^^^
test.rb:7:90: W: [Corrected] Layout/EndAlignment: end at 7, 89 is not aligned with if at 5, 52.
                                                                                         end), (unless page
                                                                                         ^^^
test.rb:8:30: C: [Corrected] Layout/IndentationWidth: Use 2 (not 38) spaces for indentation.
                                                                   'disabled'
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:8:30: C: [Corrected] Layout/IndentationWidth: Use 2 (not 39) spaces for indentation.
                                                                    'disabled'
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:8:66: C: [Corrected] Layout/IndentationWidth: Use 2 (not 39) spaces for indentation.
                                                                                                        'disabled'
                                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:8:67: C: [Corrected] Layout/IndentationWidth: Use 2 (not 33) spaces for indentation.
                                                                                                   'disabled'
                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:8:97: C: [Corrected] Layout/IndentationWidth: Use 2 (not 33) spaces for indentation.
                                                                                                                                 'disabled'
                                                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:9:66: W: [Corrected] Layout/EndAlignment: end at 9, 65 is not aligned with unless at 7, 29.
                                                                 end)].join(' ')
                                                                 ^^^
test.rb:9:67: W: [Corrected] Layout/EndAlignment: end at 9, 66 is not aligned with unless at 7, 29.
                                                                  end)].join(' ')
                                                                  ^^^
test.rb:9:98: W: [Corrected] Layout/EndAlignment: end at 9, 97 is not aligned with unless at 7, 66.
                                                                                                 end)].join(' ')
                                                                                                 ^^^
test.rb:9:103: W: [Corrected] Layout/EndAlignment: end at 9, 102 is not aligned with unless at 7, 65.
                                                                                                      end)].join(' ')
                                                                                                      ^^^
test.rb:9:128: W: [Corrected] Layout/EndAlignment: end at 9, 127 is not aligned with unless at 7, 96.
                                                                                                                               end)].join(' ')
                                                                                                                               ^^^

0 files inspected, 34 offenses detected, 34 offenses corrected
Infinite loop detected in /Users/alter/test.rb and caused by Style/IfUnlessModifier -> Style/IfUnlessModifier -> Layout/EndAlignment, Layout/IndentationWidth, Style/IfUnlessModifier -> Layout/EndAlignment, Layout/IndentationWidth, Style/IfUnlessModifier
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:332:in `check_for_infinite_loop'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:315:in `block in iterate_until_no_changes'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:314:in `loop'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:283:in `do_inspection_loop'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:164:in `block in file_offenses'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:189:in `file_offense_cache'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:163:in `file_offenses'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:154:in `process_file'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:134:in `each'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:134:in `reduce'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:134:in `each_inspected_file'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:120:in `inspect_files'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/runner.rb:73:in `run'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/cli.rb:118:in `run_command'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/cli.rb:125:in `execute_runners'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/cli.rb:51:in `block in run'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/cli.rb:77:in `profile_if_needed'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/lib/rubocop/cli.rb:43:in `run'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/exe/rubocop:19:in `block in <top (required)>'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/3.2.0/benchmark.rb:311:in `realtime'
/Users/alter/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.62.0/exe/rubocop:19:in `<top (required)>'
/Users/alter/.rbenv/versions/3.2.2/bin/rubocop:25:in `load'
/Users/alter/.rbenv/versions/3.2.2/bin/rubocop:25:in `<main>'
Finished in 0.08543400000780821 seconds

RuboCop version

❯ rubocop -V
1.62.0 (using Parser 3.3.0.5, rubocop-ast 1.31.1, running on ruby 3.2.2) [arm64-darwin23]
@koic koic added the bug label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants