Skip to content

Commit

Permalink
[Fix rubocop#731] Fix an incorrect autocorrect for Rails/StripHeredoc
Browse files Browse the repository at this point in the history
  • Loading branch information
kazarin committed Jun 27, 2022
1 parent 0b7d5f3 commit 903e9c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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 offence 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 903e9c1

Please sign in to comment.