class RuboCop::Cop::Naming::HeredocDelimiterNaming

This cop checks that your heredocs are using meaningful delimiters. By default it disallows `END` and `EO*`, and can be configured through blacklisting additional delimiters.

@example

# good
<<-SQL
  SELECT * FROM foo
SQL

# bad
<<-END
  SELECT * FROM foo
END

# bad
<<-EOS
  SELECT * FROM foo
EOS

Constants

MSG

Public Instance Methods

on_heredoc(node) click to toggle source
# File lib/rubocop/cop/naming/heredoc_delimiter_naming.rb, line 31
def on_heredoc(node)
  return if meaningful_delimiters?(node)

  add_offense(node, location: :heredoc_end)
end

Private Instance Methods

blacklisted_delimiters() click to toggle source
# File lib/rubocop/cop/naming/heredoc_delimiter_naming.rb, line 53
def blacklisted_delimiters
  cop_config['Blacklist'] || []
end
delimiters(node) click to toggle source
# File lib/rubocop/cop/naming/heredoc_delimiter_naming.rb, line 49
def delimiters(node)
  node.source.match(OPENING_DELIMITER).captures.first
end
meaningful_delimiters?(node) click to toggle source
# File lib/rubocop/cop/naming/heredoc_delimiter_naming.rb, line 39
def meaningful_delimiters?(node)
  delimiters = delimiters(node)

  return false unless delimiters =~ /\w/

  blacklisted_delimiters.none? do |blacklisted_delimiter|
    delimiters =~ Regexp.new(blacklisted_delimiter)
  end
end