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/FirstArgumentIndentation is off-by-[1|2] when using splats with chained methods #9155

Closed
pdobb opened this issue Dec 2, 2020 · 0 comments · Fixed by #9159
Closed
Labels

Comments

@pdobb
Copy link
Contributor

pdobb commented Dec 2, 2020

This is a follow-up to #9115.

There is still/another issue in rubocop 1.5.1 with splatting and the Layout/MultilineMethodCallIndentation cop with EnforcedStyle: consistent_relative_to_receiver.


Expected behavior

Both of these examples should be valid:

# Valid :)
[
  value1,
  *my_method(
    arg1)
]

# Invalid :(
[
  *my_object
    .my_chained_method(
      arg1)
]

Actual behavior

Method chains appear to require an extra space to offset the splat operator.

# This is considered invalid, when it shouldn't be
[
  *my_object
    .my_chained_method1(
      arg1)
]

C: Layout/MultilineMethodCallIndentation: Indent .my_chained_method 2 spaces more than my_object on line 4.
    .my_chained_method1(
    ^^^^^^^^^^^^^^^^^^

# And will autocorrect to this, when it shouldn't (Note the extra space before `.my_chained_method(`
[
  *my_object
     .my_chained_method1(
      arg1)
]

Also:

# This is considered invalid, when it shouldn't be
{
  **my_object
    .my_chained_method2(
      arg1)
}

C Layout/MultilineMethodCallIndentation: Indent .my_chained_method 2 spaces more than my_object on line 4.
    .my_chained_method2(
    ^^^^^^^^^^^^^^^^^^

# And will autocorrect to this, when it shouldn't (Note the extra 2 spaces before `.my_chained_method(`
{
  **my_object
      .my_chained_method2(
      arg1)
}

Steps to reproduce the problem

Add to temp file and lint with rubocop --only Layout/MultilineMethodCallIndentation temp.rb

[
  *my_object
    .my_chained_method(
      arg1)
]

{
  **my_object
    .my_chained_method(
      arg1)
}

Note, that my configuration is:

Layout/FirstArgumentIndentation:
EnforcedStyle: consistent_relative_to_receiver

RuboCop version

$ rubocop -V
1.5.1 (using Parser 2.7.2.0, rubocop-ast 1.3.0, running on ruby 2.6.6 x86_64-darwin19)
  - rubocop-performance 1.9.0
  - rubocop-rails 2.8.1
  - rubocop-rake 0.5.1
@koic koic added the bug label Dec 3, 2020
koic added a commit to koic/rubocop that referenced this issue Dec 3, 2020
…llIndentation`

Fixes rubocop#9155.

This PR fixes a false positive for `Layout/MultilineMethodCallIndentation`
when multiline method chain has expected indent width and the method is
preceded by splat for `EnforcedStyle: indented_relative_to_receiver`
bbatsov pushed a commit that referenced this issue Dec 3, 2020
…tation`

Fixes #9155.

This PR fixes a false positive for `Layout/MultilineMethodCallIndentation`
when multiline method chain has expected indent width and the method is
preceded by splat for `EnforcedStyle: indented_relative_to_receiver`
koic added a commit to koic/rubocop that referenced this issue Dec 3, 2020
Follow rubocop#9154,
rubocop#9155,
and rubocop#9102.

This is a step towards the widespread use of regexp_parser 2.0.

RuboCop core accepts regexp_parser 1.8, but several code is already
incompatible with regexp_parser 1.8. It can cause issue because these
combination of versions.

Therefore, this PR ports code for regexp_parser 1.8 that will never be
maintained from rubocop#9102.

Implementation of this patch, code is intentionally duplicated because
it is evaluated only when the class is defined. Also, since obsoleted
code for regexp_parser 1.8 is assumed to never be maintained, the target
to be removed is clear.

To be honest, it's ugly as implementation, but I think it has the least
impact for RuboCop 1.x series users.
bbatsov pushed a commit that referenced this issue Dec 3, 2020
Follow #9154,
#9155,
and #9102.

This is a step towards the widespread use of regexp_parser 2.0.

RuboCop core accepts regexp_parser 1.8, but several code is already
incompatible with regexp_parser 1.8. It can cause issue because these
combination of versions.

Therefore, this PR ports code for regexp_parser 1.8 that will never be
maintained from #9102.

Implementation of this patch, code is intentionally duplicated because
it is evaluated only when the class is defined. Also, since obsoleted
code for regexp_parser 1.8 is assumed to never be maintained, the target
to be removed is clear.

To be honest, it's ugly as implementation, but I think it has the least
impact for RuboCop 1.x series users.
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.

2 participants