Sha256: c11c340ad1be5e8d08de6ea506b7cc04f65d63439899ab9ddfa041e9cc4087b7

Contents?: true

Size: 816 Bytes

Versions: 7

Compression:

Stored size: 816 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
          !/" | \\[^'\\] | \#[@{$]/x.match?(src)
        end
      end

      def preferred_string_literal
        enforce_double_quotes? ? '""' : "''"
      end

      def enforce_double_quotes?
        string_literals_config['EnforcedStyle'] == 'double_quotes'
      end

      def string_literals_config
        config.for_cop('Style/StringLiterals')
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-1.69.2 lib/rubocop/cop/mixin/string_literals_help.rb
rubocop-1.69.1 lib/rubocop/cop/mixin/string_literals_help.rb
rubocop-1.69.0 lib/rubocop/cop/mixin/string_literals_help.rb
rubocop-1.68.0 lib/rubocop/cop/mixin/string_literals_help.rb
rubocop-1.67.0 lib/rubocop/cop/mixin/string_literals_help.rb
rubocop-1.66.1 lib/rubocop/cop/mixin/string_literals_help.rb
rubocop-1.66.0 lib/rubocop/cop/mixin/string_literals_help.rb