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

Layout/EmptyLineAfterGuardClause doesn't seem to play nice with heredoc and return #9852

Closed
byronbowerman opened this issue Jun 4, 2021 · 1 comment · Fixed by #9876
Closed
Labels

Comments

@byronbowerman
Copy link

Be clear, concise and precise in your description of the problem.
Open an issue with a descriptive title and a summary in grammatically correct,
complete sentences.

Use the template below when reporting bugs. Please, make sure that
you're running the latest stable RuboCop and that the problem you're reporting
hasn't been reported (and potentially fixed) already.

Before filing the ticket you should replace all text above the horizontal
rule with your own words.

Similar to the examples in #7378, I am seeing an unexpected offense when using heredoc with a guard clause. I think this might be related to #7796.


Expected behavior

Describe here how you expected RuboCop to behave in this particular situation.

No offense registered in this example:

def foo
  puts(<<~END.squish) and return unless guard?
    A multiline message
    that will be squished.
  END

  return_value
end

Actual behavior

Describe here what actually happened.
Please use rubocop --debug when pasting rubocop output as it contains additional information.

The above example code produces this offense:

def foo
  puts(<<~END.squish) and return unless guard?
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add empty line after guard clause.
    A multiline message
    that will be squished.
  END

  return_value
end

unless I start my heredoc with a blank line, e.g.:

def foo
    puts(<<~END.squish) and return unless guard?

    A multiline message
    that will be squished.
  END

  return_value
end

Steps to reproduce the problem

This is extremely important! Providing us with a reliable way to reproduce
a problem will expedite its solution.

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler.
If you see extension cop versions (e.g. rubocop-performance, rubocop-rspec, and others)
output by rubocop -V, include them as well. Here's an example:

bundle exec rubocop -V
1.12.1 (using Parser 3.0.1.1, rubocop-ast 1.5.0, running on ruby 2.6.6 x86_64-darwin20)
  - rubocop-performance 1.7.1
  - rubocop-rails 2.10.1
  - rubocop-rspec 2.3.0
@AndreiEres
Copy link

@koic #9876

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.

3 participants