If the arguments of a method call span more than one line, only allow one argument per line
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- ruby
- Domain
- documentation
Research direction
Start by reviewing the Method Arguments Alignment section of the Ruby Style Guide and the linked Layout/ArgumentAlignment documentation. Compare the proposed examples with the existing guidance, including the possible array and hash rules, and determine whether this belongs in the style guide or as a RuboCop cop or configuration option. Done requires an agreed rule and documented scope.
Written by the indexing model from the issue text.
Description
I wonder what people would think of extending Method Arguments Alignment (or perhaps creating a new guideline) to include the following rule: If the arguments of a method call span more than one line, only allow one argument per line.
Here are some code examples based on the Method Arguments Alignment guideline I linked above:
# bad
def send_mail(source)
Mailer.deliver(to: '[email protected]', from: '[email protected]', subject: 'Important message',
body: source.text)
end
# bad (normal indent)
def send_mail(source)
Mailer.deliver(
to: '[email protected]', from: '[email protected]', subject: 'Important message',
body: source.text
)
end
# good
def send_mail(source)
Mailer.deliver(to: '[email protected]',
from: '[email protected]',
subject: 'Important message',
body: source.text)
end
# good (normal indent)
def send_mail(source)
Mailer.deliver(
to: '[email protected]',
from: '[email protected]',
subject: 'Important message',
body: source.text
)
end
what do you think?
Pros:
- IMO, it looks better.
- Makes diffs easier to read when you're only changing specific arguments of a method call.
- If turned into an autocorrectable cop/configuration option in RuboCop, it could improve the results of formatting with the Layout/LineLength cop. Right now when a method call extends past the line length character limit, oftentimes it will cut off the last argument and put it on the next line, with all the other arguments still on the original line, which looks awkward, especially with DSLs.
Cons:
- Might be considered overly restrictive.
- If you have a method which takes a ton of arguments (probably too many), then it might be nice to not have the method call take up too many lines. (that said, in this case, I would still prefer each argument on its own line to make diffs easier to read)
Sidenote - We could also add corresponding rules for Array and Hash alignment, but I wanted to start with this one since I wasn't 100% sure about those.
I was originally planning on opening an issue in https://github.com/rubocop/rubocop, but after looking through some of the feature request issue there it seems like this is the better repository to start in. Let me know if it would be better to raise this issue as a new cop idea in RuboCop instead.
Also, even if we decide that this isn't the right fit for the ruby style guide, we could still maybe add a configuration option to Layout/ArgumentAlignment which is disabled by default, or a new cop which is disabled by default, which allows users to enforce this this.
- Dominant language
- No language data
- Stars
- 16.5k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rubocop/ruby-style-guide
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
rubocop/ruby-style-guide#984 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
rubocop/ruby-style-guide#982 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
rubocop/ruby-style-guide#884 · 3 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
rubocop/ruby-style-guide#961 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
rubocop/ruby-style-guide#957 ·
All issues in rubocop/ruby-style-guide
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
microsoft/onnxruntime#33018 ·
Maintainers usually reply within 2 days
-
missing content writing algorithms
Difficulty 1/5 Under an hour Newbie friendliness 88/100
QuantConnect/Documentation#2739 ·
Maintainers usually reply within 1 day
-
:watch: Not Triaged dotnet-target-version
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
copilot documentation
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
lichess-org/api#678 ·