Skip to content

Commit

Permalink
Merge pull request #733 from kazarin/fix_incorrect_autocorrect_for_ra…
Browse files Browse the repository at this point in the history
…ils_strip_heredoc

[Fix #731] Fix an incorrect autocorrect for Rails/StripHeredoc
  • Loading branch information
koic authored Jun 28, 2022
2 parents da37010 + c26b36c commit 0c18551
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#731](https://github.com/rubocop/rubocop-rails/issues/731): Fix an incorrect autocorrect for `Rails/StripHeredoc`. ([@kazarin][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/strip_heredoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def on_send(node)

def register_offense(node, heredoc)
add_offense(node) do |corrector|
squiggly_heredoc = heredoc.source.sub(/\A<<-?/, '<<~')
squiggly_heredoc = heredoc.source.sub(/\A<<(-|~)?/, '<<~')

corrector.replace(heredoc, squiggly_heredoc)
corrector.remove(node.loc.dot)
Expand Down
15 changes: 15 additions & 0 deletions spec/rubocop/cop/rails/strip_heredoc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@
RUBY
end

it 'registers an offense when squiggly already present' do
expect_offense(<<~RUBY)
<<~EOS.strip_heredoc
^^^^^^^^^^^^^^^^^^^^ Use squiggly heredoc (`<<~`) instead of `strip_heredoc`.
some text
EOS
RUBY

expect_correction(<<~RUBY)
<<~EOS
some text
EOS
RUBY
end

it 'does not register an offense when using squiggly heredoc' do
expect_no_offenses(<<~RUBY)
<<~EOS
Expand Down

0 comments on commit 0c18551

Please sign in to comment.