Sha256: 80d762422503e509d8d02d48f1e2eae81fb825956734b7a65ec52d95188dcf73

Contents?: true

Size: 753 Bytes

Versions: 6

Compression:

Stored size: 753 Bytes

Contents

# encoding: utf-8

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

      def wrong_quotes?(node, style)
        src = node.loc.expression.source
        return false if src.start_with?('%') || src.start_with?('?')
        if style == :single_quotes
          src !~ /'/ && src !~ StringHelp::ESCAPED_CHAR_REGEXP
        else
          src !~ /" | \\ | \#/x
        end
      end

      def autocorrect(node)
        lambda do |corrector|
          replacement = node.loc.begin.is?('"') ? "'" : '"'
          corrector.replace(node.loc.begin, replacement)
          corrector.replace(node.loc.end, replacement)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/mixin/string_literals_help.rb
rubocop-0.35.0 lib/rubocop/cop/mixin/string_literals_help.rb
rubocop-0.34.2 lib/rubocop/cop/mixin/string_literals_help.rb
rubocop-0.34.1 lib/rubocop/cop/mixin/string_literals_help.rb
rubocop-0.34.0 lib/rubocop/cop/mixin/string_literals_help.rb
rubocop-0.33.0 lib/rubocop/cop/mixin/string_literals_help.rb