forked from rubocop/rubocop
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix rubocop#10689] Fix autocorrect for `Layout/FirstHashElementInden…
…tation` and `Layout/FirstArrayElementIndentation` Fixes rubocop#10689 This PR fixes the autocorrect for `Layout/FirstHashElementIndentation` and `Layout/FirstArrayElementIndentation` each combined with `Layout/HashAlignment`. The new behavior indents the elements of a hash in a hash (or an array in a hash) based on the parent hash key _when the parent hash is a method argument and has a following other sibling pair_. Example code to be corrected: ```ruby func x: { a: 1, b: 2 }, y: { # following sibling pair in the parent hash c: 1, d: 2 } ``` In the original behavior, the code is corrected like ```ruby func x: { a: 1, b: 2 }, y: { # following sibling pair of the parent hash c: 1, d: 2 } ``` With this fix, the code is corrected like ```ruby func x: { a: 1, b: 2 }, y: { # following sibling pair in the parent hash c: 1, d: 2 } ``` The autocorrect keeps the original behavior when the parent hash has no other following pairs. (I could change this so that the elements of the hash are always indented based on the parent hash key, but I kept the original behavior this time) ```ruby func x: { a: 1, b: 2 } func x: { a: 1, b: 2 } ```
- Loading branch information
Showing
7 changed files
with
530 additions
and
32 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
changelog/fix_autocorrect_for_first_hash_element_indentation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#10689](https://github.com/rubocop/rubocop/issues/10689): Fix autocorrect for `Layout/FirstHashElementIndentation` and `Layout/FirstArrayElementIndentation`. ([@j-miyake][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.