diff options
-rw-r--r-- | rubocop/cop/line_break_around_conditional_block.rb | 7 | ||||
-rw-r--r-- | spec/rubocop/cop/line_break_around_conditional_block_spec.rb | 16 |
2 files changed, 22 insertions, 1 deletions
diff --git a/rubocop/cop/line_break_around_conditional_block.rb b/rubocop/cop/line_break_around_conditional_block.rb index 59fe6e5d98c..8118b314b63 100644 --- a/rubocop/cop/line_break_around_conditional_block.rb +++ b/rubocop/cop/line_break_around_conditional_block.rb @@ -77,7 +77,8 @@ module RuboCop start_clause_line?(previous_line(node)) || block_start?(previous_line(node)) || begin_line?(previous_line(node)) || - assignment_line?(previous_line(node)) + assignment_line?(previous_line(node)) || + rescue_line?(previous_line(node)) end def last_line_valid?(node) @@ -111,6 +112,10 @@ module RuboCop line =~ /^\s*.*=/ end + def rescue_line?(line) + line =~ /^\s*rescue/ + end + def block_start?(line) line.match(/ (do|{)( \|.*?\|)?\s?$/) end diff --git a/spec/rubocop/cop/line_break_around_conditional_block_spec.rb b/spec/rubocop/cop/line_break_around_conditional_block_spec.rb index 03eeffe6483..892b393c307 100644 --- a/spec/rubocop/cop/line_break_around_conditional_block_spec.rb +++ b/spec/rubocop/cop/line_break_around_conditional_block_spec.rb @@ -328,6 +328,22 @@ describe RuboCop::Cop::LineBreakAroundConditionalBlock do expect(cop.offenses).to be_empty 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 source = <<~RUBY def a_method |