ruby-style-guide icon indicating copy to clipboard operation
ruby-style-guide copied to clipboard

Usage of do...end block syntax in conditionals

Open adi-pen opened this issue 4 years ago • 1 comments

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?

adi-pen avatar Jan 06 '21 18:01 adi-pen

Both exampes look extremely awkward.

Would you like to send a pull request?

pirj avatar Feb 25 '21 17:02 pirj