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

Block-level rescue + semantic block style => syntax error #7836

Closed
grncdr opened this issue Apr 1, 2020 · 1 comment · Fixed by #10042
Closed

Block-level rescue + semantic block style => syntax error #7836

grncdr opened this issue Apr 1, 2020 · 1 comment · Fixed by #10042

Comments

@grncdr
Copy link

grncdr commented Apr 1, 2020

When using the semantic style with Style/BlockDelimiters rubocop will create a syntax error in functional blocks containing a rescue clause.

Expected behavior

Rubocop should never replace do / end delimiters on blocks if they contain a block-level rescue clause.

Actual behavior

Here is a repo showing the issue: https://github.com/grncdr/rubocop-semantic-block-issue

But to summarize, with semantic block style Rubocop turns this:

# frozen_string_literal: true
foo = [].map do |x|
  x.something_dangerous!
rescue StandardError => e
  puts 'oh no'
end

into this:

# frozen_string_literal: true

foo = [].map { |x|
  x.something_dangerous!
rescue StandardError => e
  puts 'oh no'
}

Steps to reproduce the problem

git clone https://github.com/grncdr/rubocop-semantic-block-issue
cd rubocop-semantic-block-issue
bundle
bundle exec rubocop --safe-auto-correct

RuboCop version

bundle exec rubocop -V
0.81.0 (using Parser 2.7.0.5, running on ruby 2.6.3 x86_64-darwin19)
tejasbubane added a commit to tejasbubane/rubocop that referenced this issue Apr 4, 2020
With `semantic` style, do not autocorrect to braces if block contains
`rescue` or `ensure`.

Closes rubocop#7836
@stale
Copy link

stale bot commented Sep 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

@stale stale bot added the stale Issues that haven't been active in a while label Sep 29, 2020
@marcandre marcandre removed the stale Issues that haven't been active in a while label Nov 7, 2020
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Aug 25, 2021
…nd` when converting a block containing `rescue` or `ensure` to braces.
bbatsov pushed a commit that referenced this issue Aug 26, 2021
…n converting a block containing `rescue` or `ensure` to braces.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants