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

[Fix #10751] Fix autocorrect for Layout/FirstHashElementIndentation #10759

Merged

Conversation

j-miyake
Copy link
Contributor

@j-miyake j-miyake commented Jun 28, 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

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

With the parenthesis and special_inside_parentheses style

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

With the parenthesis and consistent style

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

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@j-miyake j-miyake force-pushed the fix_layout_first_hash_element_indentation branch from a399fc1 to cf91d1f Compare June 28, 2022 06:11
@j-miyake j-miyake marked this pull request as ready for review June 28, 2022 06:32
…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)
```
@j-miyake j-miyake force-pushed the fix_layout_first_hash_element_indentation branch from cf91d1f to 9ca3076 Compare June 28, 2022 08:44
Copy link
Contributor

@bquorning bquorning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@bbatsov bbatsov merged commit bcf90de into rubocop:master Jun 29, 2022
@bbatsov
Copy link
Collaborator

bbatsov commented Jun 29, 2022

Well done!

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 this pull request may close these issues.

Possible bug in Layout/FirstHashElementIndentation
3 participants