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

Style/BlockDelimiters forces do-end style even if it were one liner #11117

Closed
ym19851201 opened this issue Oct 24, 2022 · 1 comment · Fixed by #11118
Closed

Style/BlockDelimiters forces do-end style even if it were one liner #11117

ym19851201 opened this issue Oct 24, 2022 · 1 comment · Fixed by #11118
Labels

Comments

@ym19851201
Copy link

I found a bug related to Style/BlockDelimters


Expected behavior

I hoped Rubocop didn't offend the code below.

def method
  ary&.map { |e| some_func(e) }&.find { |e| some_func2(e) }
end

Actual behavior

But actually, it's overwritten by RuboCop like below.

def method
  ary&.map do |e| some_func(e) end&.find { |e| some_func2(e) }
end

And rubocop --debug said

For /current/directory: configuration from /path/to/.rubocop.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection

Steps to reproduce the problem

  1. Set Style/BlockDelimiters EnforcedStyle: semantic
  2. Chain some methods with at least one safe navigation operator
    Probably, it should be in a method. On the top level, it seems another kind of bug occurs against method chain. (It's under investigation now)
  3. Run RuboCop
  4. All pairs of {} in the chain except last one will be offended

RuboCop version

$ [bundle exec] rubocop -V
1.37.1 (using Parser 3.1.2.1, rubocop-ast 1.23.0, running on ruby 3.1.2) [arm64-darwin21]
@ym19851201 ym19851201 changed the title Style/BlockDelimiters forces do end style even if it were one liner Style/BlockDelimiters forces do-end style even if it were one liner Oct 24, 2022
@koic koic added the bug label Oct 24, 2022
koic added a commit to koic/rubocop that referenced this issue Oct 24, 2022
Fixes rubocop#11117.

This PR fixes a false positive for `Style/BlockDelimiters`
when specifying `EnforcedStyle: semantic` and using a single line block
with {} followed by a safe navigation method call.
bbatsov pushed a commit that referenced this issue Oct 25, 2022
Fixes #11117.

This PR fixes a false positive for `Style/BlockDelimiters`
when specifying `EnforcedStyle: semantic` and using a single line block
with {} followed by a safe navigation method call.
@ym19851201
Copy link
Author

Thank you!

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