Skip to content

Commit

Permalink
[Fix #7094] Clarify alignment in MultilineOperationIndentation
Browse files Browse the repository at this point in the history
Update the cop documentation to make it more clear which operands should be
aligned, and which should always be indented.
  • Loading branch information
jonas054 authored and bbatsov committed Apr 19, 2020
1 parent 0bc7b80 commit 3c0e5b5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@
### Changes

* [#7860](https://github.com/rubocop-hq/rubocop/issues/7860): Change `AllowInHeredoc` option of `Layout/TrailingWhitespace` to `true` by default. ([@koic][])
* [#7094](https://github.com/rubocop-hq/rubocop/issues/7094): Clarify alignment in `Layout/MultilineOperationIndentation`. ([@jonas054][])

## 0.82.0 (2020-04-16)

Expand Down
17 changes: 13 additions & 4 deletions lib/rubocop/cop/layout/multiline_operation_indentation.rb
Expand Up @@ -6,30 +6,39 @@ module Layout
# This cop checks the indentation of the right hand side operand in
# binary operations that span more than one line.
#
# The `aligned` style checks that operators are aligned if they are part
# of an `if` or `while` condition, a `return` statement, etc. In other
# contexts, the second operand should be indented regardless of enforced
# style.
#
# @example EnforcedStyle: aligned (default)
# # bad
# if a +
# b
# something
# something &&
# something_else
# end
#
# # good
# if a +
# b
# something
# something &&
# something_else
# end
#
# @example EnforcedStyle: indented
# # bad
# if a +
# b
# something
# something &&
# something_else
# end
#
# # good
# if a +
# b
# something
# something &&
# something_else
# end
#
class MultilineOperationIndentation < Cop
Expand Down
17 changes: 13 additions & 4 deletions manual/cops_layout.md
Expand Up @@ -3736,6 +3736,11 @@ Enabled | Yes | Yes | 0.49 | -
This cop checks the indentation of the right hand side operand in
binary operations that span more than one line.

The `aligned` style checks that operators are aligned if they are part
of an `if` or `while` condition, a `return` statement, etc. In other
contexts, the second operand should be indented regardless of enforced
style.

### Examples

#### EnforcedStyle: aligned (default)
Expand All @@ -3744,13 +3749,15 @@ binary operations that span more than one line.
# bad
if a +
b
something
something &&
something_else
end

# good
if a +
b
something
something &&
something_else
end
```
#### EnforcedStyle: indented
Expand All @@ -3759,13 +3766,15 @@ end
# bad
if a +
b
something
something &&
something_else
end

# good
if a +
b
something
something &&
something_else
end
```

Expand Down

0 comments on commit 3c0e5b5

Please sign in to comment.