Commit 93d5d768 authored by Stan Hu's avatar Stan Hu

Merge branch '33220-fix-cop-line-break-around-conditional-block' into 'master'

Fix Cop/LineBreakAroundConditionalBlock for block+comment

Closes #33220

See merge request gitlab-org/gitlab!18002
parents dab68b06 b56edbf0
...@@ -117,7 +117,7 @@ module RuboCop ...@@ -117,7 +117,7 @@ module RuboCop
end end
def block_start?(line) def block_start?(line)
line.match(/ (do|{)( \|.*?\|)?\s?$/) line.match(/ (do|{)( \|.*?\|)?\s?(#.+)?\z/)
end end
def end_line?(line) def end_line?(line)
......
...@@ -132,6 +132,19 @@ describe RuboCop::Cop::LineBreakAroundConditionalBlock do ...@@ -132,6 +132,19 @@ 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 block definition with a comment" do
source = <<~RUBY
on_block(param_a) do |item| # a short comment
#{conditional} condition
do_something
end
end
RUBY
inspect_source(source)
expect(cop.offenses).to be_empty
end
it "doesn't flag violation for #{conditional} preceded by a block definition using brackets" do it "doesn't flag violation for #{conditional} preceded by a block definition using brackets" do
source = <<~RUBY source = <<~RUBY
on_block(param_a) { |item| on_block(param_a) { |item|
......
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