Skip to content

Commit

Permalink
issue-359: No hanging indentation
Browse files Browse the repository at this point in the history
Based off of a very old issue that had a lot of interesting discussion:

rubocop#359

The idea here is that hanging indentation is incredibly hard to read while going down a page, and also incurs extra editing whenever more methods are added to a chain.
  • Loading branch information
baweaver committed Aug 15, 2018
1 parent 0e5ce53 commit 90ede77
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,6 @@ Translations of the guide are available in the following languages:
body: source.text)
end

# good
def send_mail(source)
Mailer.deliver(to: 'bob@example.com',
from: 'us@example.com',
subject: 'Important message',
body: source.text)
end

# good (normal indent)
def send_mail(source)
Mailer.deliver(
Expand All @@ -643,6 +635,41 @@ Translations of the guide are available in the following languages:
end
```

* <a name="no-hanging-indent"></a>
Use a new line for the argument list of a method at the end of a chain
if they are indented more than one level from the first method.
<sup>[[link](#no-hanging-indent)]</sup>

```ruby
# bad (hanging indent)
some_method.with.a_longer.chain(:parameter_1,
:parameter_2,
:parameter_3,
:parameter_4)

# good (newline indent)
some_method.with.a_longer.chain(
:parameter_1,
:parameter_2,
:parameter_3,
:parameter_4
)

# good (multiple methods with newline indent)
very_long_kumquats =
some_method
.with
.a_much_much_much_much_much
.longer
.chain(
:parameter_1,
:parameter_2,
:parameter_3,
:parameter_4
)
```


* <a name="align-multiline-arrays"></a>
Align the elements of array literals spanning multiple lines.
<sup>[[link](#align-multiline-arrays)]</sup>
Expand Down

0 comments on commit 90ede77

Please sign in to comment.