rubocop / rubocop/ruby-style-guide

Usage of do...end block syntax in conditionals

Open
#859 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Help Wanted New Rule
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

  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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.