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 one when the method is preceded by a * #9115

Closed
pdobb opened this issue Nov 28, 2020 · 0 comments · Fixed by #9117
Closed

Layout/FirstArgumentIndentation is off by one when the method is preceded by a * #9115

pdobb opened this issue Nov 28, 2020 · 0 comments · Fixed by #9117
Labels

Comments

@pdobb
Copy link
Contributor

pdobb commented Nov 28, 2020

I am experiencing an off-by-1 disagreement with the Layout/FirstArgumentIndentation cop (configured with EnforcedStyle: consistent_relative_to_receiver) when a leading * is involved. But preceding dots and &. behave fine.

# Valid
[
  value1,
  my_object
    .my_method(
      arg1)  # 2 spaces from start of `.my_method`
]

# Valid
[
  value1,
  my_object
    &.my_method(
      arg1)  # 2 spaces from start of `&.my_method`
]

# Invalid :(
[
  value1,
  *my_method(
    arg1)  # 2 spaces from start of `*my_method`
]

Expected behavior

Layout/FirstArgumentIndentation shouldn't auto-correct to and shouldn't require an extra space when an * precedes the method call.

Actual behavior

# This is considered invalid, when it shouldn't be
[
  value1,
  *my_method(
    arg1,  # 2 spaces from start of `*my_method`
    arg2)
]

temp.rb:23:5: C: Layout/FirstArgumentIndentation: Indent the first argument one step more than my_method(.
    arg1,
    ^^^^

# And will autocorrect to this, when it shouldn't (Note the extra / 3rd space before `arg1`
[
  1,
  *my_method(
     arg1,  # 3 spaces from start of `*my_method`
    arg2)
]

Steps to reproduce the problem

Just add this to a ruby file and run the Layout/FirstArgumentIndentation cop

[
  value1,
  *my_method(
    arg1)
]

Note, that my configuration is:

Layout/FirstArgumentIndentation:
  EnforcedStyle: consistent_relative_to_receiver

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:

$ rubocop -V
1.4.2 (using Parser 2.7.2.0, rubocop-ast 1.2.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 Nov 29, 2020
koic added a commit to koic/rubocop that referenced this issue Nov 29, 2020
…tation`

Fixes rubocop#9115.

This PR fixes a false positive for `Style/FirstArgumentIndentation` when
argument has expected indent width and the method is preceded by splat
for `EnforcedStyle: consistent_relative_to_receiver`.
bbatsov pushed a commit that referenced this issue Nov 29, 2020
Fixes #9115.

This PR fixes a false positive for `Style/FirstArgumentIndentation` when
argument has expected indent width and the method is preceded by splat
for `EnforcedStyle: consistent_relative_to_receiver`.
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