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
Autocorrect for Layout/FirstHashElementIndentation
breaks indentation consistency
#10689
Comments
The error message says C: [Correctable] Layout/FirstHashElementIndentation: Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.
description: 'Validates your identity',
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The second hash key |
…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 } ```
… and `Layout/FirstArrayElementIndentation` Fixes #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 } ```
…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) ```
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) ```
The autocorrect for
Layout/FirstHashElementIndentation
breaks indentation consistency when inspecting this code.(Code borrowed from grape's README)
Expected behavior
No offenses, or correct the code with keeping indentation consistency for the second hash element.
Actual behavior
The code is autocorrected like,
Steps to reproduce the problem
Run rubocop against the above code with the default configuration.
RuboCop version
The text was updated successfully, but these errors were encountered: