rubocop: Layout/EndAlignment does not flag misaligned begin..rescue..end block

Layout/EndAlignment cop should treat a begin..rescue block similar to if..else

Expected behavior

Expected RuboCop to flag the incorrect alignment of end with keyword begin or rescue. Expected to get following output:

rubocop test.rb
W

Offenses:

test.rb:8:7: C: Layout/IndentationWidth: Use 2 (not -4) spaces for indentation.
      raisable_method
      ^^^^
test.rb:11:5: W: Layout/EndAlignment: end at 11, 4 is not aligned with begin at 7, 10.
    end
    ^^^

1 file inspected, 2 offenses detected

Actual behavior

rubocop test.rb
.

1 file inspected, no offenses detected

Steps to reproduce the problem

# test.rb
# frozen_string_literal: true

# Dummy Class
class Foo
  def bar
    res = begin
      raisable_method
          rescue StandardError
            fall_back
    end
    res
  end
end

RuboCop version

$ [bundle exec] rubocop -V
0.64.0 (using Parser 2.6.0.0, running on ruby 2.4.4 x64-mingw32)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

I’ll close this issue because the subject issue resolved by the latest RuboCop.

I think the begin..rescue..end case is now handled by the new cops Layout/BeginEndAlignment and Layout/RescueEnsureAlignment. Please note that the default setting for Layout/BeginEndAlignment is different.

I just tested the original case with RuboCop 0.89 (see this gist) and the default configuration, and it still detects no offenses. Setting either EnforcedStyleAlignWith: variable or start_of_line has no effect.