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/FirstArrayElementIndentation-20240209233127 #914

Merged
merged 4 commits into from
May 30, 2024

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Feb 9, 2024

Rubocop challenge!

Layout/FirstArrayElementIndentation

Safe autocorrect: Yes
✅ The autocorrect a cop does is safe (equivalent) by design.

Description

Overview

Checks the indentation of the first element in an array literal
where the opening bracket and the first element are on separate lines.
The other elements' indentations are handled by Layout/ArrayAlignment cop.

This cop will respect Layout/ArrayAlignment and will not work when
EnforcedStyle: with_fixed_indentation is specified for Layout/ArrayAlignment.

By default, array literals that are arguments in a method call with
parentheses, and where the opening square bracket of the array is on the
same line as the opening parenthesis of the method call, shall have
their first element indented one step (two spaces) more than the
position inside the opening parenthesis.

Other array literals shall have their first element indented one step
more than the start of the line where the opening square bracket is.

This default style is called 'special_inside_parentheses'. Alternative
styles are 'consistent' and 'align_brackets'. Here are examples:

Examples

EnforcedStyle: special_inside_parentheses (default)

# The `special_inside_parentheses` style enforces that the first
# element in an array literal where the opening bracket and first
# element are on separate lines is indented one step (two spaces) more
# than the position inside the opening parenthesis.

# bad
array = [
  :value
]
and_in_a_method_call([
  :no_difference
                     ])

# good
array = [
  :value
]
but_in_a_method_call([
                       :its_like_this
                     ])

EnforcedStyle: consistent

# The `consistent` style enforces that the first element in an array
# literal where the opening bracket and the first element are on
# separate lines is indented the same as an array literal which is not
# defined inside a method call.

# bad
# consistent
array = [
  :value
]
but_in_a_method_call([
                       :its_like_this
])

# good
array = [
  :value
]
and_in_a_method_call([
  :no_difference
])

EnforcedStyle: align_brackets

# The `align_brackets` style enforces that the opening and closing
# brackets are indented to the same position.

# bad
# align_brackets
and_now_for_something = [
                          :completely_different
]

# good
# align_brackets
and_now_for_something = [
                          :completely_different
                        ]

Auto generated by rubocop_challenger

@mathieujobin mathieujobin merged commit 77b075e into master May 30, 2024
50 checks passed
@mathieujobin mathieujobin deleted the rubocop-challenge/20240209233127 branch May 30, 2024 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant