-
-
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
Indent for an expression spanning multiple lines #1646
Comments
If I'm not mistaken, it's not the AlignParameters cop that complains here, but instead MultilineOperationIndentation. |
Sorry for the long break in communications. Using the following .rubocop.yml still results in the complaints about indentation.
I included the complaints below for reference, I hope this is just a configuration issue on our side!
|
No, you can't solve this with configuration, unless you want to disable the cop. Looking at this issue and at #1633, it seems to me that multiline method call chains should be checked by a separate cop, as people have different expectations and preferences for expressions like the one above compared to things like some_instance.member.attributes =
some_value +
new_class_member +
params[:some_key] |
Is this solved with @jonas054's new |
Not exactly. The current Style/MultilineMethodCallIndentation:
EnforcedStyle: indented RuboCop accepts some_instance.member.attributes = SomeService
.new(@class_member)
.permit_method_call(params[:some_key]) and some_instance.member.attributes =
SomeService
.new(@class_member)
.permit_method_call(params[:some_key]) With Style/MultilineMethodCallIndentation:
EnforcedStyle: aligned it accepts some_instance.member.attributes = SomeService
.new(@class_member)
.permit_method_call(params[:some_key]) and some_instance.member.attributes = SomeService.new(@class_member)
.permit_method_call(params[:some_key]) and some_instance.member.attributes =
SomeService
.new(@class_member)
.permit_method_call(params[:some_key]) |
@jonas054 OK, thanks. It seems like the style requested here is quite reasonable. Do you have any ideas what a 3rd style for |
Here's my understanding of what is requested. The style is a variation on the If my understanding is correct, it follows that the following indentation would be enforced, for example. some_instance.member.attributes == SomeService
.new(@class_member)
.permit_method_call(params[:some_key]) The name that springs to mind is |
I don't think this style has anything specifically to do with assignments. If the selector in a dotted method call is pushed to a following line, then you follow the chain of dotted method calls back to its root, and indent from the receiver of the first call in the chain. So the example you gave is right. But so are these: if Something
.call1
.call2
while Something
.call1
.call2
class A < Something
.call |
@elyzion, does that seem to describe what you are looking for? |
Looking forward to a style that allows:
(using the 4 char standard continued indentation from Rubymine) |
Could we call this style |
I'd go for long and wordy. How about |
Has there been any progress on this issue? In our projects we're now disabling this cop as we're normally writing our code What we'd like to have is a cop which enforces the following code style: my_variable = MyClass
.method_1(123)
.method_2 If no one is working on this, I might have a look in how to make this possible myself. |
I'm not sure I'm reading the code correctly, but shouldn't it almost handle this case already? @nicolas-fricke I'd love to help out, we're also disabling this cop because of this same issue. |
Yes, almost being the operative word. What you see there is alignment where the right hand side of the expression ( |
…ver style Add the style indented_relative_to_receiver in Style/MultilineMethodCallIndentation for indentation of method calls so that each new line of a call chain is indented one step more than the ultimate receiver.
Thanks @jonas054 for taking care of this – looking forward to upgrading rubocop to the next version and then reenabling this new cop :) |
…ver style (rubocop#3233) Add the style indented_relative_to_receiver in Style/MultilineMethodCallIndentation for indentation of method calls so that each new line of a call chain is indented one step more than the ultimate receiver.
Rubocop complains about the indentation on the .new and .permit_method_call lines in the code snippet below. Aligning the calls with the some_instance line resolves the complaints, but in this case it should be calculating the indent from the SomeService line. I am using version 0.29.0.
I also included my .rubocop.yml below. Is this a Rubocop limitation, or is it something I can resolve with my configuration? (I tried the indent and align configuration options to no avail.)
The text was updated successfully, but these errors were encountered: