rubocop: Unexpected Layout/ClosingParenthesisIndentation behavior with non-standard indententation

I’m not sure how this doesn’t fail in the specs but with 0.57.1, the basic “good” case for Layout/ClosingParenthesisIndentation raises an error.

This looks like it’s related to changed for Issue #4136 (I see no related PR). Likely something in 68609e6 which appears to be the (large) commit related to that effort.


Expected behavior

Given the following file:

# frozen_string_literal: true

some_method(
    a,
    b
)

I would expect rubocop to accept that code. It’s exactly what is described in the documentation example.

Actual behavior

Rubocop raises an error:

$ rubocop close-paren.rb 
Inspecting 1 file
C

Offenses:

close-paren.rb:6:1: C: Layout/ClosingParenthesisIndentation: Indent ) to column 2 (not 0)
)
^

1 file inspected, 1 offense detected

Steps to reproduce the problem

See above.

RuboCop version

$ rubocop -v
0.57.1

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 25 (11 by maintainers)

Most upvoted comments

Ah, that explains why the error didn’t show up in the specs.

The indentation of the parameters is a matter of style controlled by Layout/FirstParameterIndentation.

We use this in our styles:

Layout/FirstParameterIndentation:
  IndentationWidth: 4

My understanding of the rule is that the closing parenthesis should be indented to match the start of the line that opened it. That’s what the rule used to say.

This looks good to me:

some_method(
    a,
    b
)

This looks bad:

some_method(
    a,
    b
  )

So Layout/ClosingParenthesisIndentation should not be making assumptions about the indentation as that’s controlled by another rule, right?