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/ArgumentAlignment/with_fixed_indentation doesn't apply in nested method calls #10830

Closed
jdufresne opened this issue Jul 24, 2022 · 0 comments · Fixed by #10840
Closed
Labels

Comments

@jdufresne
Copy link
Contributor

Expected behavior

With Layout/ArgumentAlignment set to with_fixed_indentation, I expect that the
first argument will always be indented an additional level from the method call
line. When Layout/FirstMethodArgumentLineBreak, moves a argument to the next
line, I expect this new line to be indented.

Actual behavior

When method calls are nested and Layout/FirstMethodArgumentLineBreak moves the
first argument to a new line, that new line is not indented.

Steps to reproduce the problem

.rubocop.yml

AllCops:
  NewCops: enable

Layout/ArgumentAlignment:
  EnforcedStyle: with_fixed_indentation

Layout/FirstMethodArgumentLineBreak:
  Enabled: true

Style/WordArray:
  EnforcedStyle: brackets

test.rb

# frozen_string_literal: true

it do
  expect(my_method).to eq([
    'a',
    'b',
    'c'
  ])
end

Run RuboCop

$ bundle exec rubocop --debug -A test.rb
For /home/jon/test: configuration from /home/jon/test/.rubocop.yml
Default configuration from /home/jon/test/.bundle/ruby/3.1.0/gems/rubocop-1.32.0/config/default.yml
Use parallel by default.
Running parallel inspection
Loading cache from /home/jon/.cache/rubocop_cache/e062dc539034f87d925e4c6b7fb6bb1915a56b8e/6d7a3b621ca1730e04accd938619e4bdab66cfb1/fe425179b4f1deedd5a514216b91c8bc6bdcf304
Inspecting 1 file
Scanning /home/jon/test/test.rb
Loading cache from /home/jon/.cache/rubocop_cache/e062dc539034f87d925e4c6b7fb6bb1915a56b8e/6d7a3b621ca1730e04accd938619e4bdab66cfb1/fe425179b4f1deedd5a514216b91c8bc6bdcf304
C

Offenses:

test.rb:4:27: C: [Corrected] Layout/FirstMethodArgumentLineBreak: Add a line break before the first argument of a multi-line method argument list.
  expect(my_method).to eq([ ...
                          ^
test.rb:5:5: C: [Corrected] Layout/FirstArrayElementIndentation: Use 2 spaces for indentation in an array, relative to the first position after the preceding left parenthesis.
    'a',
    ^^^
test.rb:6:29: C: [Corrected] Layout/FirstArrayElementIndentation: Use 2 spaces for indentation in an array, relative to the start of the line where the left square bracket is.
                            'a',
                            ^^^
test.rb:7:5: C: [Corrected] Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
    'b',
    ^^^
test.rb:7:29: C: [Corrected] Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
                            'b',
                            ^^^
test.rb:8:3: C: [Corrected] Layout/FirstArrayElementIndentation: Indent the right bracket the same as the first position after the preceding left parenthesis.
  ])
  ^
test.rb:8:5: C: [Corrected] Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
    'c'
    ^^^
test.rb:8:29: C: [Corrected] Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
                            'c'
                            ^^^
test.rb:9:27: C: [Corrected] Layout/FirstArrayElementIndentation: Indent the right bracket the same as the start of the line where the left bracket is.
                          ])
                          ^
test.rb:9:28: C: [Corrected] Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.
                          ])
                           ^

1 file inspected, 10 offenses detected, 10 offenses corrected
Finished in 0.245670356991468 seconds

result

# frozen_string_literal: true

it do
  expect(my_method).to eq(
[
  'a',
  'b',
  'c'
]
)
end

expected

# frozen_string_literal: true

it do
  expect(my_method).to eq(
    [
      'a',
      'b',
      'c'
    ]
  )
end

RuboCop version

$ bundle exec rubocop -V
1.32.0 (using Parser 3.1.2.0, rubocop-ast 1.19.1, running on ruby 3.1.2 x86_64-linux)
@koic koic added the bug label Jul 24, 2022
koic added a commit to koic/rubocop that referenced this issue Jul 28, 2022
…umentIndentation`

Fixes rubocop#10830.

This PR fixes an incorrect autocorrect for `Layout/FirstArgumentIndentation` when specifying
`EnforcedStyle: with_fixed_indentation` of `Layout/ArgumentAlignment` and
`EnforcedStyle: consistent` of `Layout/FirstArgumentIndentation` and
enabling `Layout/FirstMethodArgumentLineBreak`.
koic added a commit that referenced this issue Jul 28, 2022
…layout_first_argument_indentation

[Fix #10830] Fix an incorrect autocorrect for `Layout/FirstArgumentIndentation`
WJWH pushed a commit to WJWH/rubocop that referenced this issue Aug 8, 2022
…umentIndentation`

Fixes rubocop#10830.

This PR fixes an incorrect autocorrect for `Layout/FirstArgumentIndentation` when specifying
`EnforcedStyle: with_fixed_indentation` of `Layout/ArgumentAlignment` and
`EnforcedStyle: consistent` of `Layout/FirstArgumentIndentation` and
enabling `Layout/FirstMethodArgumentLineBreak`.
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