-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[#4136] Change ClosingParenthesisIndentation to be relative to parameters #5698
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
[#4136] Change ClosingParenthesisIndentation to be relative to parameters #5698
Conversation
|
@bbatsov I'll squash these once you've had a chance to review 👍 |
|
@bbatsov Also, this single PR should close all 5 issues listed in my first commit message ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this off by 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just making it more explicit that the paren wasn't aligned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just making it more explicit that the paren wasn't aligned.
|
`If the method is called (or defined) and the arguments/parameters...
Can you provide just two basic code snippets to make sure we're on the same page about this? Btw, before we merge this we should also update the cop documentation as well. |
Looking at the diff I don't see much logic removal. 😄 |
"It's easy" - Famous Last Words 😉 There's more code, but logic itself is easier to understand IMO:
There's no more looking up what kind of style the parameters are set at and therefore no more dependency on other cops. |
|
I'll be happy to update the documentation. If you want to make sure we're on the same page, the easiest way to do that would be to just look at the tests, but here is the only example of code that Rubocop will change its results for: Beforesome_method(a,
)Aftersome_method(a,
)Not only do I think this is correct, but keeping the tests passing for this one case would have required more logic that I didn't think was worth the tradeoff. New code snippets that now work include: foo = some_method(
a
) foo = some_method(
a
)No additional configuration is required to make either of those work, they're based on allowing the parameter cops to put the parameters in the correct place and then placing the |
|
Fair enough. You'll have to rebase this, but the changes seem sound to me. Some doc updates would be appreciated. |
|
@bbatsov requested doc updates are completed. Rebased onto |
I think the best approach for this cop is to remove most of the logic and let it depend on where the parameters are aligned at. I think there should be only two rules: If the method is called (or defined) and the arguments/parameters... * that span more than one line, the closing parenthesis should be outdented by one `IndentationWidth` from the last argument/parameter * that are all on one line, the closing parenthesis should be aligned with the opening parenthesis This lets the other cops like `Layout/FirstParameterIndentation`, `Layout/FirstMethodParameterLineBreak`, `Layout/FirstMethodArgumentLineBreak`, `Layout/MultilineMethodDefinitionBraceLayout`, `Layout/MultilineMethodCallBraceLayout` and `Layout/AlignParameters` be responsible for their jobs and `Layout/ClosingParenthesisIndentation` would simply be the result of the end of that flow. By simplifying the cop, it allows for all of the cases described in #5650, all of my use cases here, and will keep almost every current `ClosingParenthesisIndentation` spec passing. References #4136, #5650, #3204, #3139, #2791
|
@bbatsov I referenced all the relevant issue numbers that this issue closes in my first commit message but didn't explicitly close them there in case you had other opinions, so if you agree, that will have to be done manually. |
|
👍 |
I think the best approach for this cop is to remove most of the logic and
let it depend on where the parameters are aligned at. I think there should
be only two rules:
If the method is called (or defined) and the arguments/parameters...
outdented by one
IndentationWidthfrom the last argument/parameterwith the opening parenthesis
This lets the other cops like
Layout/FirstParameterIndentation,Layout/FirstMethodParameterLineBreak,Layout/FirstMethodArgumentLineBreak,Layout/MultilineMethodDefinitionBraceLayout,Layout/MultilineMethodCallBraceLayoutandLayout/AlignParametersberesponsible for their jobs and
Layout/ClosingParenthesisIndentationwouldsimply be the result of the end of that flow.
By simplifying the cop, it allows for all of the cases described in #5650,
all of my use cases here, and will keep almost every current
ClosingParenthesisIndentationspec passing.Before submitting the PR make sure the following are checked:
[Fix #issue-number](if the related issue exists).master(if not - rebase it).and description in grammatically correct, complete sentences.
rake defaultorrake parallel. It executes all tests and RuboCop for itself, and generates the documentation.