class RuboCop::Cop::Naming::HeredocDelimiterNaming

Checks that your heredocs are using meaningful delimiters. By default it disallows ‘END` and `EO*`, and can be configured through forbidden listing 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.loc.heredoc_end)
end

Private Instance Methods

forbidden_delimiters() click to toggle source
# File lib/rubocop/cop/naming/heredoc_delimiter_naming.rb, line 49
def forbidden_delimiters
  cop_config['ForbiddenDelimiters'] || []
end
meaningful_delimiters?(node) click to toggle source
# File lib/rubocop/cop/naming/heredoc_delimiter_naming.rb, line 39
def meaningful_delimiters?(node)
  delimiters = delimiter_string(node)

  return false unless /\w/.match?(delimiters)

  forbidden_delimiters.none? do |forbidden_delimiter|
    Regexp.new(forbidden_delimiter).match?(delimiters)
  end
end