rubocop: Align the operands of an expression in an assignment spanning multiple lines bug (or me not understanding the config)
I’m running: 0.28.0 (using Parser 2.2.0.2, running on ruby 2.0.0 x86_64-darwin14.0.0)
With the code:
users = User.where(email: 'user@example.com').
update_all(user_parameters)
I get the rubocop warning:
Align the operands of an expression in an assignment spanning multiple lines
It passes with this which I feel isn’t correct indentation:
users = User.where(email: 'user@example.com').
update(user_parameters)
I’m not sure if this is a bug or my error.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 3
- Comments: 26
Commits related to this issue
- Fix rules for indenting multiline assignments https://trello.com/c/8plKSKKM See https://github.com/bbatsov/rubocop/issues/1633 — committed to houndci/hound by c-lliope 9 years ago
- I prefer indented b/c I like long variable names. https://github.com/bbatsov/rubocop/issues/1633#issuecomment-73067109 — committed to q-centrix/hound by deleted user 9 years ago
- disabled Style/MultilineOperationIndentation see https://github.com/bbatsov/rubocop/issues/1633#issuecomment-73067109 — committed to Nix-wie-weg/rubocop-nww by deleted user 9 years ago
- [Fix #1633] Add MultilineMethodCallIndentation Move responsibility for checking method call indentation from MultilineOperationIndentation to this new cop. — committed to jonas054/rubocop by jonas054 9 years ago
- Merge pull request #2493 from jonas054/multiline_indentation [Fix #1633] Add MultilineMethodCallIndentation — committed to rubocop/rubocop by bbatsov 9 years ago
@rafalchmiel Why not simply use one method call per line?
You should keep in mind this is expression continuation and the expression starts with the first receiver. I understand your reasoning, but it seems flawed to me. There’s also the fact few editors support the indentation you suggest.
Style/MultilineOperationIndentationcan be configured with thealignedstyle (default), which enforcesand
indented, which enforcesThe
alignedstyle is supported by ruby-mode 1.1 in Emacs andindentedis another common style.So I wouldn’t say that there’s a bug in RuboCop here. The behavior is intended. To support your style, which I wouldn’t rule out at this point, we’d have to add a third alternative. Maybe call is
semanticsince it tries to convey a meaning relating to a call chain? I have a suspicion there might be a few corner cases with this new style that I can’t describe in detail right now, but I don’t know.Being able to verticaly align method calls when they are related can ease the understanding, in my opinion.
For instance with this dummy exemple:
It seems to me more self explanatory than the rubocop compliant:
In rails, this situation happen when you have severals query/scope: