Commit 24fc2377 authored by Robert Speicher's avatar Robert Speicher

Fix LineBreakAroundConditionalBlock cop for a conditional after rescue

Previously this would violate on the `if`:

    def a_method
      do_something
    rescue
      if condition
        do_something
      end
    end
parent ba99dfcd
...@@ -77,7 +77,8 @@ module RuboCop ...@@ -77,7 +77,8 @@ module RuboCop
start_clause_line?(previous_line(node)) || start_clause_line?(previous_line(node)) ||
block_start?(previous_line(node)) || block_start?(previous_line(node)) ||
begin_line?(previous_line(node)) || begin_line?(previous_line(node)) ||
assignment_line?(previous_line(node)) assignment_line?(previous_line(node)) ||
rescue_line?(previous_line(node))
end end
def last_line_valid?(node) def last_line_valid?(node)
...@@ -111,6 +112,10 @@ module RuboCop ...@@ -111,6 +112,10 @@ module RuboCop
line =~ /^\s*.*=/ line =~ /^\s*.*=/
end end
def rescue_line?(line)
line =~ /^\s*rescue/
end
def block_start?(line) def block_start?(line)
line.match(/ (do|{)( \|.*?\|)?\s?$/) line.match(/ (do|{)( \|.*?\|)?\s?$/)
end end
......
...@@ -328,6 +328,22 @@ describe RuboCop::Cop::LineBreakAroundConditionalBlock do ...@@ -328,6 +328,22 @@ describe RuboCop::Cop::LineBreakAroundConditionalBlock do
expect(cop.offenses).to be_empty expect(cop.offenses).to be_empty
end end
it "doesn't flag violation for #{conditional} preceded by a rescue" do
source = <<~RUBY
def a_method
do_something
rescue
#{conditional} condition
do_something
end
end
RUBY
inspect_source(source)
expect(cop.offenses).to be_empty
end
it "doesn't flag violation for #{conditional} followed by a rescue" do it "doesn't flag violation for #{conditional} followed by a rescue" do
source = <<~RUBY source = <<~RUBY
def a_method def a_method
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment