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/CommentIndentation raises false positives in method calls #2975

Closed
ajvondrak opened this issue Mar 22, 2016 · 0 comments
Closed

Style/CommentIndentation raises false positives in method calls #2975

ajvondrak opened this issue Mar 22, 2016 · 0 comments

Comments

@ajvondrak
Copy link

I have a multiline method call where the parameters to the method are on separate lines. I want to exclude the last parameter of this call from simplecov. The way you do that is to surround the line with # :nocov: comments. However, this triggers a false positive for Style/CommentIndentation:

/tmp$ cat repro.rb
method.call(
  :foo,
  :bar,
  # :nocov:
  :baz
  # :nocov:
)
/tmp$ rubocop -V
0.38.0 (using Parser 2.3.0.6, running on ruby 2.3.0 x86_64-darwin13)
/tmp$ cat .rubocop.yml # default config
cat: .rubocop.yml: No such file or directory
/tmp$ rubocop -D repro.rb 
Inspecting 1 file
C

Offenses:

repro.rb:6:3: C: Style/CommentIndentation: Incorrect indentation detected (column 2 instead of 0).
  # :nocov:
  ^^^^^^^^^

1 file inspected, 1 offense detected

It seems like Style/CommentIndentation is trying to group the second # :nocov: comment with the following line (the closing paren), since the following formatting passes:

method.call(
  :foo,
  :bar,
  # :nocov:
  :baz
# :nocov:
)

which (I think everyone would agree) looks bad.

Does this generalize? Should Style/CommentIndentation simply adhere to the preceding line's indentation if the following line is a closing paren or something like that? It seems to already do that for hashes & arrays, like:

/tmp$ cat does_not_fail.rb 
{
  foo: 'foo',
  bar: 'bar',
  # :nocov:
  baz: 'baz'
  # :nocov:
}

[
  :foo,
  :bar,
  # :nocov:
  :baz
  # :nocov:
]
/tmp$ rubocop -D --only Style/CommentIndentation does_not_fail.rb 
Inspecting 1 file
.

1 file inspected, no offenses detected
jonas054 added a commit to jonas054/rubocop that referenced this issue Apr 2, 2016
We already had special handling of comments before closing curly
brace and closing square bracket. Handle a closing round parenthesis
the same way, which is that the comment should be indented one step
more than the following line.
@bbatsov bbatsov closed this as completed in 88276a8 Apr 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant