-
Notifications
You must be signed in to change notification settings - Fork 1
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
Indentation of closing parenthesis with hash argument #3
Comments
This issue is also discussed here: rubocop/rubocop#1758 |
Our discussion focused around the method call in your example, for which good alternatives exist. However, I find the cop's behavior weird even when it works as intended:
Hence I vote for disable. |
Rubocop's bad indentation in this case can currently not be fixed, afaik. It stems from the method call spreading across multiple lines in this case, and Rubocop's suggested fix is definitely ugly, but any alternative will work and IMHO look better. However, don't be fooled by the cop's intent. It will catch bad indentation like this: def func(
x,
y
) I vote for keeping. Ideally, Rubocop will have an option that disables indenting closing parenthesis further than necessary in the future. Rubocop would then not be able to auto-correct and developer's would not be confronted with a failed attempt to fix something. |
Bonus solution: contract_attributes = {
moderator: moderator,
city_department: city_department,
}
create(:moderator_contract, contract_attributes) IMHO more readable and flexible. |
Also vote for disable. I consider
the nicest solution (i don't like introducing an additional local variable either). While it is a bit unfortunate that we have no cop checking for the indentation at all, I don't feel like misplaced closing parens are a common problem or cause for disagreement. |
I would like to keep this cop. The positive effect outweigh the edge cases. Using factories with the pattern above is nice. But I also saw styles like:
Here it's really hard to notice the |
I don't like the suggested indentation of a closing parenthesis when a method is called with a hash argument.
The indentation is caused by the first argument
{
being on the same line as the method call.https://www.rubydoc.info/github/bbatsov/RuboCop/RuboCop/Cop/Layout/ClosingParenthesisIndentation
A very common occurence for this correction is the use of FactoryGirl factories:
One solution to consider is to not use curly braces for argument hashes, e.g.:
and for factories to move the factory argument to a separate line:
The text was updated successfully, but these errors were encountered: