[Proposal] Use `EnforcedStyle: consistent` for indentation rules
Reported in gitlab-org/gitlab!99808 (comment 1122868118)
By default FirstArrayElementIndentation prefers EnforcedStyle: special_inside_parentheses. That's also true for other cop rules (see below).
#good
array = [
:value
]
but_in_a_method_call([
:its_like_this
])
But I believe in our code style we try to avoid an excessive right-indentation for methods. The better match can be EnforcedStyle: consistent.
#good
array = [
:value
]
and_in_a_method_call([
:no_difference
])
Larger code example
With current settings
# frozen_string_literal: true
module Namespaced
class Test
field :ci_config_variables, [Types::Ci::ConfigVariableType],
null: true,
calls_gitaly: true,
authorize: :create_pipeline,
alpha: { milestone: '15.3' }
def arrays(
foo,
baz,
bar)
longer_name = [1,
2]
a_very_decriptive_method_name([
add,
longer_name
])
end
def hashes
a_very_decriptive_method_name(x: {
key: value,
nesting: {
is: :fun
}
})
end
def nested_calls
foo = some_method(
first_param,
second_param)
foo + 1
end
end
end
With proposed changes
# frozen_string_literal: true
module Namespaced
class Test
field :ci_config_variables, [Types::Ci::ConfigVariableType],
null: true,
calls_gitaly: true,
authorize: :create_pipeline,
alpha: { milestone: '15.3' }
def arrays(
foo,
baz,
bar)
longer_name = [1,
2]
a_very_decriptive_method_name([
add,
longer_name
])
end
def hashes
a_very_decriptive_method_name(x: {
key: value,
nesting: {
is: :fun
}
})
end
def nested_calls
foo = some_method(
first_param,
second_param)
foo + 1
end
end
end
Proposal
Consider changing the configuration for the following cop rules:
| Cop |
EnforcedStyle After |
EnforcedStyle Before |
|---|---|---|
Layout/FirstArgumentIndentation |
consistent |
special_for_inner_method_call_in_parentheses |
Layout/FirstArrayElementIndentation |
consistent |
special_inside_parentheses |
Layout/FirstHashElementIndentation |
consistent |
special_inside_parentheses |
Layout/ArgumentAlignment (disabled) |
with_fixed_indentation |
with_first_argument |
Layout/ArrayAlignment |
with_fixed_indentation |
with_first_parameter |
Layout/ParameterAlignment |
with_fixed_indentation |
with_first_parameter |
Proof of concept
Edited by Peter Leitzen