-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Issue when combining ClosingParenthesisIndentation and AlignParameters:with_fixed_indentation #1758
Comments
That's not a style worth supporting IMO as it's not exactly common. To be honest I've never seen Ruby code indented like this until just now... |
I'm not sure how this code can be formatted then, given this combination of configurations. I could disable one of the cops, I guess :-) |
Pretty sure the only two common indentation schemes for this bit of code are: puts(1,
foo: 'bar',
one: 'two')
puts(
1,
foo: 'bar',
one: 'two'
) |
Just chiming in that I've seen this style used with some frequency when a method has a single initial parameter that is not a hash, followed by hash parameters. Example from some Factory Girl code in a Rails project: create(:store,
name: 'Downtown Boutique',
address: '123 Main St, Anytown, USA'
) To me at least, the equivalent cop-compliant code is harder to read, because the initial parameter is given the same visual "precedence" as the hash parameters, even though it is a completely separate and more important element: create(
:store,
name: 'Downtown Boutique',
address: '123 Main St, Anytown, USA'
) I have no strong opinion on whether this exact style should be enforceable via Rubocop, but as it stands, merely using the style means that you have to forego |
+1 |
And one of the two you show is what @bquorning is asking for... |
Whoops, I was wrong. Sorry, @bbatsov. |
I can code up a PR for this, but what should the config parameter which enables this style in |
Ping. Do we want this style added to |
Would this style also apply for method definitions and grouped expressions? I think we (or the person doing the implementation) need to see all examples before we can decide on what to call the configuration parameter/values. For reference, here's what's currently accepted: some_method(
a
)
x = some_method(
a
)
x =
some_method(
a
)
some_method(a
)
some_method()
def some_method(
a
)
end
private def some_method(
a
)
end
private def some_method(a
)
end
def some_method(a
)
end
def some_method()
end
w = x * (
y + z
)
w = x * (y + z
)
w = x * (y + z +
a)
w = x * (y + z +
a
) |
👍 |
@bquorning, what do you think of @jonas054's comment? Are you looking for a new style specific to method calls, or should it be for grouped expressions (using parens) as well? |
What I was looking for was well described by @Grantovich as
So yes, only for method calls. |
For some real-world examples of this style in the wild, see code-dot-org/code-dot-org#7562. (We're blacklisting the |
We use this style quite a bit when we have one (or a few) non-hash params followed by a hash or keywords. Moving the non-hash arguments to the first line muddles the distinction between what is an argument and what is in the hash. |
…meters When the with_fixed_indentation style is used by Style/AlignParameters, the hanging closing parenthesis should adapt. It's going to look weird otherwise.
…meters (rubocop#3215) When the with_fixed_indentation style is used by Style/AlignParameters, the hanging closing parenthesis should adapt. It's going to look weird otherwise.
I like to configure
Style/AlignParameters
withEnforcedStyle: with_fixed_indentation
, which would allow me code like this:On the latest master (933d084),
Style/ClosingParenthesisIndentation
tells me to indent the closing parenthesis:I could move the
1
argument to a separate line, but I would rather keep the non-hash arguments on the same line as the method call, and the options hash on separate lines. Explicitly, I guess it would be:The text was updated successfully, but these errors were encountered: