rubocop / rubocop/ruby-style-guide
Usage of do...end block syntax in conditionals
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 encountered a situation where a do...end block syntax is used as a work-around to avoid line limits.
Example:
# frozen_string_literal: true
if [].any? do |variable|
# do something
end
true
end
Indenting the block by one level helps identify the end of the conditional easily but still does not feel natural at least to me. This results in a Layout/BlockAlignment offense.
# frozen_string_literal: true
if [].any? do |variable|
# do something
end
true
end
Could we enforce that do..end blocks are not used in conditionals or have a style-preference if we support it?
Contributor guide
No contributing guide indexed for this repository
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.
Research direction
No file or test is named. Start by reviewing the repository’s existing guidance for conditionals, blocks, and Layout/BlockAlignment, then compare the two examples and document a clear policy for do...end blocks in conditionals; done means the guide states whether this syntax is prohibited or preferred.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- documentation
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100