Skip to content

Commit

Permalink
[Fix rubocop#11998] Fix an error when inspecting blank heredoc delimiter
Browse files Browse the repository at this point in the history
Fixes rubocop#11998.

This PR fixes an error when inspecting blank heredoc delimiter.
  • Loading branch information
koic committed Jun 29, 2023
1 parent aaf1c3f commit d054077
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11998](https://github.com/rubocop/rubocop/issues/11998): Fix an error when inspecting blank heredoc delimiter. ([@koic][])
8 changes: 6 additions & 2 deletions lib/rubocop/cop/mixin/heredoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ def indent_level(str)
end

def delimiter_string(node)
node.source.match(OPENING_DELIMITER).captures[1]
return '' unless (match = node.source.match(OPENING_DELIMITER))

match.captures[1]
end

def heredoc_type(node)
node.source.match(OPENING_DELIMITER).captures[0]
return '' unless (match = node.source.match(OPENING_DELIMITER))

match.captures[0]
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/naming/heredoc_delimiter_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@
RUBY
end
end

context 'when using blank heredoc delimiters' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
<<''
RUBY
end
end
end

context 'with a squiggly heredoc' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,10 @@
EOS
RUBY
end

it 'does not register an offense when using the blank heredoc delimiter' do
expect_no_offenses(<<~RUBY)
<<''
RUBY
end
end

0 comments on commit d054077

Please sign in to comment.