class RuboCop::Cop::Style::EmptyHeredoc
do_something(”)
# good
EOS
do_something(<<EOS)
EOS
do_something(<<-EOS)
EOS
do_something(<<~EOS)
# bad
”
# good
EOS
<<EOS
EOS
<<-EOS
EOS
<<~EOS
# bad
@example
Checks for using empty heredoc to reduce redundancy.
def enforce_double_quotes?
def enforce_double_quotes? string_literals_config['EnforcedStyle'] == 'double_quotes' end
def on_heredoc(node)
def on_heredoc(node) heredoc_body = node.loc.heredoc_body return unless heredoc_body.source.empty? add_offense(node) do |corrector| heredoc_end = node.loc.heredoc_end corrector.replace(node, preferred_string_literal) corrector.remove(range_by_whole_lines(heredoc_body, include_final_newline: true)) corrector.remove(range_by_whole_lines(heredoc_end, include_final_newline: true)) end end
def preferred_string_literal
def preferred_string_literal enforce_double_quotes? ? '""' : "''" end
def string_literals_config
def string_literals_config config.for_cop('Style/StringLiterals') end