ruby / prism

Prism Ruby parser
https://ruby.github.io/prism/
MIT License
792 stars 134 forks source link

Heredoc flagged with `Layout/HeredocIndentation` creates infinite loop in rubocop #2848

Closed CKolkey closed 1 month ago

CKolkey commented 1 month ago

Prism version: v0.29.0 Rubocop version: 1.64.0

With this file:

# frozen_string_literal: true

{
  "content" => <<~XML.strip,
    <section>
      Hello
    </section>
  XML
}

This error is flagged: Screenshot 2024-05-28 at 10 16 34

And attempting to fix it with ruby-lsp (rubocop) yields:

LSP[ruby_lsp] Formatting error: Infinite loop detected in ./prism_bug.rb and caused by Layout/ExtraSpacing, Layout/SpaceAroundMethodCallOperator
Hint: Please update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version.

Using bundle exec rubocop -a prism_bug.rb results in a step-by-step breakdown of the states:

prism_bug.rb:4:23: C: [Corrected] Layout/ExtraSpacing: Unnecessary spacing detected.
  "content" => <<~XML.    strip,
                      ^^^
prism_bug.rb:4:23: C: [Corrected] Layout/HeredocIndentation: Use 2 spaces for indentation in a heredoc.
  "content" => <<~XML.strip, ...
                      ^^^^^^
prism_bug.rb:4:23: C: [Corrected] Layout/SpaceAroundMethodCallOperator: Avoid using spaces around a method call operator.
  "content" => <<~XML.    strip,
                      ^^^^

0 files inspected, 3 offenses detected, 3 offenses corrected
Infinite loop detected in .prism_bug.rb and caused by Layout/ExtraSpacing, Layout/SpaceAroundMethodCallOperator
Hint: Please update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version.
Please check the latest version at https://rubygems.org/gems/rubocop.
kddnewton commented 1 month ago

This is now fixed on main and will be released soon

CKolkey commented 1 month ago

Thanks - keep up the great work :)