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

Auto-correction for Style/RedundantParentheses breaks heredoc string syntax #10895

Closed
justisb opened this issue Aug 9, 2022 · 0 comments · Fixed by #10896
Closed

Auto-correction for Style/RedundantParentheses breaks heredoc string syntax #10895

justisb opened this issue Aug 9, 2022 · 0 comments · Fixed by #10896
Assignees
Labels

Comments

@justisb
Copy link

justisb commented Aug 9, 2022

The Style/RedundantParentheses cop auto-correction causes invalid syntax for a heredoc string used in an array or hash, as the autocorrect adds the comma to the end of the heredoc end marker, breaking the marker.

Seems related to PR #10885.


Expected behavior

Rubocop should leave the parentheses and comma, or otherwise keep the syntax valid.

Actual behavior

The auto-correct removes the parentheses and adds a comma to the end of the heredoc marker, resulting in invalid syntax.

Steps to reproduce the problem

Example:

    [
      (
        <<-'HEREDOC'
          Foo
        HEREDOC
      ),
      (
        <<-'HEREDOC'
          Bar
        HEREDOC
      ),
    ]

Is improperly autocorrected to:

    [
      
        <<-'HEREDOC'
          Foo
        HEREDOC,
      
        <<-'HEREDOC'
          Bar
        HEREDOC,
    ]

RuboCop version

1.34.1 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 2.7.6 arm64-darwin21)
  - rubocop-graphql 0.14.5
  - rubocop-performance 1.14.3
  - rubocop-rails 2.15.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.12.1
  - rubocop-thread_safety 0.4.4
@dvandersluis dvandersluis self-assigned this Aug 9, 2022
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Aug 9, 2022
…entheses` when a heredoc is used in an array.
koic added a commit that referenced this issue Aug 10, 2022
[Fix #10895] Fix incorrect autocomplete in `Style/RedundantParentheses` when a heredoc is used in an array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants