Sha256: e7803e40459154c943711205dd5a111af820fde76051372035fb7af07549c119

Contents?: true

Size: 804 Bytes

Versions: 2

Compression:

Stored size: 804 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Common functionality for cops checking single/double quotes.
    module StringLiteralsHelp
      private

      def wrong_quotes?(src_or_node)
        src = src_or_node.is_a?(RuboCop::AST::Node) ? src_or_node.source : src_or_node
        return false if src.start_with?('%', '?')

        if style == :single_quotes
          !double_quotes_required?(src)
        else
          # The string needs single quotes if:
          # 1. It contains a double quote
          # 2. It contains text that would become an escape sequence with double quotes
          # 3. It contains text that would become an interpolation with double quotes
          !/" | (?<!\\)\\[abcefMnrtuUx0-7] | \#[@{$]/x.match?(src)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-1.22.2 lib/rubocop/cop/mixin/string_literals_help.rb
rubocop-1.22.1 lib/rubocop/cop/mixin/string_literals_help.rb