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

safe-auto-correct breaks the code #10563

altherlex opened this issue Apr 21, 2022 · 3 comments · Fixed by #10564

safe-auto-correct breaks the code #10563

altherlex opened this issue Apr 21, 2022 · 3 comments · Fixed by #10564


Copy link

altherlex commented Apr 21, 2022

Applied rubocop -a and it broken code:


      consume_diets ={|p| p.change == "consume" and !all_ignore.include?}.map{|a| [a.disease_measure_name,]} {|d| d[1]}.compact
      consume_diets2 ={|p| p.change == "consume" and !all_ignore.include?}.map{|a| [a.disease_measure_name,]}.group_by{|c| c[1].name} {|d| d[1]}.compact
      consume_diets_by_diet_id ={|p| p.change == "consume" and !all_ignore.include?}.map{|a| [a.disease_measure_identifier,]}.group_by{|c| c[1].id} {|d| d[1]}.compact
      consume_diet_ids = {|d|}


      consume_diets = do |p|
                        p.change == 'consume' and !all_ignore.include?
             do |a|
             { |d| d[1] }.compact
      consume_diets2 = # .map {|d| d[1]}.compact do |p|
          p.change == 'consume' and !all_ignore.include?
      consume_diets_by_diet_id = # .map {|d| d[1]}.compact do |p|
          p.change == 'consume' and !all_ignore.include?
      consume_diet_ids = { |d| }
Copy link

dvandersluis commented Apr 21, 2022

Can you specify which cop caused a problem and what the problem is?

Copy link

altherlex commented Apr 21, 2022

problem is that var consume_diets2 and consume_diets_by_diet_id have part of the code deleted

code deleted by rubocop -a (no extra config):

{|a| [a.disease_measure_name,]}.group_by{|c| c[1].name} {|d| d[1]}.compact

I think the cop is something related to indentation.

Thought to publish it here. It might be a good case scenario to improve even more this awesome gem.

Copy link

nobuyo commented Apr 22, 2022

It seems to be caused by Style/BlockDelimiters if method chain with block and comment like following case:

it 'registers an offense when there is a comment after the closing brace and block body is not empty' do
  expect_offense(<<~RUBY) { |x|
            ^ Avoid using `{...}` for multi-line blocks.
    foo(x) }.map { |x| x.quux } # comment

    # comment do |x|
    foo(x) { |x| x.quux }

The case returns result:

@@ -1,6 +1,4 @@
# comment do |x|
-foo(x) { |x| x.quux }

nobuyo added a commit to nobuyo/rubocop that referenced this issue Apr 22, 2022
…block on moving comment if methods with block are chained
@koic koic added the bug label Apr 23, 2022
koic added a commit that referenced this issue Apr 23, 2022

[Fix #10563] Fix `Style/BlockDelimiters` unexpectedly deletes block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging a pull request may close this issue.

4 participants