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

Bad autocorrect for Style/GuardClause with heredoc #11239

Closed
vlad-pisanov opened this issue Dec 6, 2022 · 0 comments · Fixed by #11242
Closed

Bad autocorrect for Style/GuardClause with heredoc #11239

vlad-pisanov opened this issue Dec 6, 2022 · 0 comments · Fixed by #11242
Labels

Comments

@vlad-pisanov
Copy link

Consider

if cond
  foo
else
  raise <<~EOF
    oops
  EOF
end

Autocorrect for Style/GuardClause generates the non-equivalent:

raise <<~EOF unless cond
  foo


    oops
  EOF

Expected behavior

Probably something like

raise <<~EOF unless cond
  oops
EOF
foo

RuboCop version

1.39.0 (using Parser 3.1.3.0, rubocop-ast 1.24.0, running on ruby 2.6.9) [x86_64-darwin21]
  - rubocop-minitest 0.24.0
  - rubocop-performance 1.15.1
  - rubocop-rails 2.17.3

@koic koic added the bug label Dec 7, 2022
koic added a commit to koic/rubocop that referenced this issue Dec 7, 2022
## Summary

Fixes rubocop#11239.

This PR fixes an incorrect autocorrect for `Style/GuardClause`
when using heredoc as an argument of raise in branch body.

## Other Information

Let `Layout/HeredocIndentation`, `Layout/ClosingHeredocIndentation`, and
`Layout/IndentationConsistency` cops autocorrect inconsistent indentations.
@bbatsov bbatsov closed this as completed in 52eaa84 Dec 7, 2022
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