rubocop / rubocop/ruby-style-guide

Hanging Indentation on methods

Open
#359 15 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
No language data
Stars
16.5k
Forks
3.3k
PR merge metrics
No merged PRs in 30d

Description

I'd like to propose an addendum. Often times when one has a longer method, you have to do something with the parameters to get the method under 120 lines. One method of doing this is hanging indentation, which is very distracting when trying to grok a larger code base. It breaks the flow of reading.

# Bad - Hanging Indentation
some_method.with.a_longer.chain(:parameter_1,
                                :parameter_2,
                                :parameter_3,
                                :parameter_4)

# Good - Drop to a new line
some_method.with.a_longer.chain(
  :parameter_1,
  :parameter_2,
  :parameter_3,
  :parameter_4
)

Now granted the example is mildly confounded and you shouldn't chain methods that long. That being said, it's not unusual to see hanging indentations on 1-2 method chains past the 80th column which makes it near impossible to quickly skim over things.

Can we consider adding this to the guide?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the guide section covering indentation and method-call formatting, then compare its existing rules with the hanging-indentation examples in this issue. Done means the guide clearly addresses this style and includes an appropriate example.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.