Rubocop: Layout/ClosingHeredocIndentation false positive

Created on 7 Jun 2018  路  3Comments  路  Source: rubocop-hq/rubocop

Expected behavior

Consider the following example:

def f
  puts <<-STR
 There's one space before this line
  STR
end

Expected behavior is no offenses should be detected.

P.S. The one space in above example can be removed, while in that case another cop (Layout/IndentHeredoc) will be detected, the space is added to prevent being confused.

P.S.2 If there're two spaces before the line, this bug will not present.

Actual behavior

One offense is found:

C: Layout/ClosingHeredocIndentation: STR is not aligned with puts <<-STR or beginning of method definition.
  STR
^^^^^

And if using auto-correct, rubocop -a
It shows:

Offenses:

a.rb:4:1: C: [Corrected] Layout/ClosingHeredocIndentation: STR is not aligned with puts <<-STR or beginning of method definition.
  STR
^^^^^

1 file inspected, 1 offense detected, 1 offense corrected

While NO changes is applied.

Steps to reproduce the problem

Prepare a.rb:

def f
  puts <<-STR
 There's one space before this line
  STR
end

Then run rubocop a.rb

And rubocop a.rb -a as well.

RuboCop version

$ rubocop -V
0.57.1 (using Parser 2.5.1.0, running on ruby 2.5.1 x86_64-linux)
bug

Most helpful comment

Yes. I fully agree with @rrosenblum 's suggestion. I'm also considering the same thing.

Originally, the reason for adding this function was that codes using squiggly heredoc was oddly changed by auto-correct. However, as indicated in this issue, I didn't consider case for simple heredoc that without strip_heredoc orstrip_indent.

I opened a PR #6003 that fixes the false positives indicated in this issue. Thank you for mentioning.

All 3 comments

@koic any thoughts on this. It looks like you explicitly added this functionality to Layout/ClosingHeredocIndentation in #5943.

I feel like the functionality should be removed from Layout/ClosingHeredocIndentation since this deals with indentation of the content not the closing.

My case: https://github.com/rubocop-hq/rubocop/pull/5785/files#diff-baed2d2b771e7f18f6472d08d6eae96eR369

Yes. I fully agree with @rrosenblum 's suggestion. I'm also considering the same thing.

Originally, the reason for adding this function was that codes using squiggly heredoc was oddly changed by auto-correct. However, as indicated in this issue, I didn't consider case for simple heredoc that without strip_heredoc orstrip_indent.

I opened a PR #6003 that fixes the false positives indicated in this issue. Thank you for mentioning.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

millisami picture millisami  路  3Comments

joromir picture joromir  路  3Comments

AndreiMotinga picture AndreiMotinga  路  3Comments

NobodysNightmare picture NobodysNightmare  路  3Comments

herwinw picture herwinw  路  3Comments