Sha256: 638578ad21583469a6a0b03d757ca63931a3b3637c8ed2054ae0a24b4ddc230c

Contents?: true

Size: 991 Bytes

Versions: 46

Compression:

Stored size: 991 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for interpolation in a single quoted string.
      #
      # @example
      #
      #   # bad
      #
      #   foo = 'something with #{interpolation} inside'
      #
      # @example
      #
      #   # good
      #
      #   foo = "something with #{interpolation} inside"
      class InterpolationCheck < Cop
        MSG = 'Interpolation in single quoted string detected. '\
              'Use double quoted strings if you need interpolation.'

        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

        def heredoc?(node)
          node.loc.is_a?(Parser::Source::Map::Heredoc) ||
            (node.parent && heredoc?(node.parent))
        end
      end
    end
  end
end

Version data entries

46 entries across 27 versions & 3 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/interpolation_check.rb
rubocop-0.81.0 lib/rubocop/cop/lint/interpolation_check.rb
rubocop-0.80.1 lib/rubocop/cop/lint/interpolation_check.rb
rubocop-0.80.0 lib/rubocop/cop/lint/interpolation_check.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/interpolation_check.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/interpolation_check.rb
rubocop-0.79.0 lib/rubocop/cop/lint/interpolation_check.rb
rubocop-0.78.0 lib/rubocop/cop/lint/interpolation_check.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/lint/interpolation_check.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/lint/interpolation_check.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/lint/interpolation_check.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/lint/interpolation_check.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/interpolation_check.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cop/lint/interpolation_check.rb
rubocop-0.77.0 lib/rubocop/cop/lint/interpolation_check.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/lint/interpolation_check.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/interpolation_check.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/lint/interpolation_check.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/lint/interpolation_check.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/lint/interpolation_check.rb