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

Possible bug in Layout/FirstHashElementIndentation #10751

Closed
bquorning opened this issue Jun 27, 2022 · 2 comments · Fixed by #10759
Closed

Possible bug in Layout/FirstHashElementIndentation #10751

bquorning opened this issue Jun 27, 2022 · 2 comments · Fixed by #10759

Comments

@bquorning
Copy link
Contributor

@bquorning bquorning commented Jun 27, 2022

After 023e0ea the behavior of Layout/FirstHashElementIndentation changed for the consistent style. Where code like this used to be accepted

post :create, params: {
  foo: { bar: 'Baz' }
}, as: :json

it now fails with

Offenses:

test.rb:2:3: C: [Correctable] Layout/FirstHashElementIndentation: Use 2 spaces for indentation in a hash, relative to the parent hash key.
  foo: { bar: 'Baz' }
  ^^^^^^^^^^^^^^^^^^^
test.rb:3:1: C: [Correctable] Layout/FirstHashElementIndentation: Indent the right brace the same as the parent hash key.
}, as: :json
^

Autocorrecting changes the code into

post :create, params: {
                foo: {
                  bar: 'Baz'
                }
              }, as: :json

which (at least I thought) isn’t the intended behavior for consistent style.

RuboCop version

$ ./exe/rubocop -V
1.31.0 (using Parser 3.1.2.0, rubocop-ast 1.18.0, running on ruby 2.7.6 x86_64-darwin20)
  - rubocop-performance 1.14.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.11.1
(sha 02d0dcf5606b7903978cfa6582c81f951f45e751)
@bquorning
Copy link
Contributor Author

@bquorning bquorning commented Jun 27, 2022

cc @j-miyake

@j-miyake
Copy link
Contributor

@j-miyake j-miyake commented Jun 28, 2022

You're right. That's an unintended behavior since params and as don't have to be aligned with each other in this case.

j-miyake added a commit to j-miyake/rubocop that referenced this issue Jun 28, 2022
j-miyake added a commit to j-miyake/rubocop that referenced this issue Jun 28, 2022
j-miyake added a commit to j-miyake/rubocop that referenced this issue Jun 28, 2022
j-miyake added a commit to j-miyake/rubocop that referenced this issue Jun 28, 2022
…ation

Fixes rubocop#10751

`Layout/FirstHashElementIndentation` should allow a hash where the content of the first pair is indented relative to the base column specified with configured cop style, and the second pair begins on the same line with the right brace of the first pair; because those two keys won't be aligned with each other by `Layout/HashAlignment`, not like the case of rubocop#10689.

With no parenthesis
```ruby
post :create, params: {
  foo: { bar: 'Baz' }
}, as: :json
```

With the parenthesis and `special_inside_parentheses` style
```ruby
post(:create, params: {
       foo: { bar: 'Baz' }
     }, as: :json)
```

With the parenthesis and `consistent` style
```ruby
post(:create, params: {
  foo: { bar: 'Baz' }
}, as: :json)
```
bbatsov pushed a commit that referenced this issue Jun 29, 2022
Fixes #10751

`Layout/FirstHashElementIndentation` should allow a hash where the content of the first pair is indented relative to the base column specified with configured cop style, and the second pair begins on the same line with the right brace of the first pair; because those two keys won't be aligned with each other by `Layout/HashAlignment`, not like the case of #10689.

With no parenthesis
```ruby
post :create, params: {
  foo: { bar: 'Baz' }
}, as: :json
```

With the parenthesis and `special_inside_parentheses` style
```ruby
post(:create, params: {
       foo: { bar: 'Baz' }
     }, as: :json)
```

With the parenthesis and `consistent` style
```ruby
post(:create, params: {
  foo: { bar: 'Baz' }
}, as: :json)
```
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

Successfully merging a pull request may close this issue.

2 participants