From 1c5106fadfe59ec4af7235b94d424e4367185c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Mon, 28 May 2018 15:00:09 +0200 Subject: Allow comment after if/unless clause MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- rubocop/cop/line_break_around_conditional_block.rb | 2 +- spec/rubocop/cop/line_break_around_conditional_block_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/rubocop/cop/line_break_around_conditional_block.rb b/rubocop/cop/line_break_around_conditional_block.rb index 3e7021e724e..8b6052fee1b 100644 --- a/rubocop/cop/line_break_around_conditional_block.rb +++ b/rubocop/cop/line_break_around_conditional_block.rb @@ -95,7 +95,7 @@ module RuboCop end def end_clause_line?(line) - line =~ /^\s*(rescue|else|elsif|when)/ + line =~ /^\s*(#|rescue|else|elsif|when)/ end def begin_line?(line) 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 7ddf9141fcd..03eeffe6483 100644 --- a/spec/rubocop/cop/line_break_around_conditional_block_spec.rb +++ b/spec/rubocop/cop/line_break_around_conditional_block_spec.rb @@ -256,6 +256,18 @@ describe RuboCop::Cop::LineBreakAroundConditionalBlock do expect(cop.offenses).to be_empty end + it "doesn't flag violation for #{conditional} followed by a comment" do + source = <<~RUBY + #{conditional} condition + do_something + end + # a short comment + RUBY + inspect_source(source) + + expect(cop.offenses).to be_empty + end + it "doesn't flag violation for #{conditional} followed by an end" do source = <<~RUBY class Foo -- cgit v1.2.3