class RuboCop::Cop::Lint::InterpolationCheck

This cop checks for interpolation in a single quoted string.

@example

# bad

foo = 'something with #{interpolation} inside'

@example

# good

foo = "something with #{interpolation} inside"

Constants

MSG

Public Instance Methods

heredoc?(node) click to toggle source
# File lib/rubocop/cop/lint/interpolation_check.rb, line 33
def heredoc?(node)
  node.loc.is_a?(Parser::Source::Map::Heredoc) ||
    (node.parent && heredoc?(node.parent))
end
on_str(node) click to toggle source
# File lib/rubocop/cop/lint/interpolation_check.rb, line 23
def on_str(node)
  return if heredoc?(node)

  parent = node.parent
  return if parent && (parent.dstr_type? || parent.regexp_type?)
  return unless node.source.scrub =~ /(?<!\\)#\{.*\}/

  add_offense(node)
end