Sha256: d3224352babde4f7de25bea996c84cdb63f9a019fc8aaa67d8090d5bab32d4bc

Contents?: true

Size: 647 Bytes

Versions: 3

Compression:

Stored size: 647 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class StringLiterals < Cop
      MSG = "Prefer single-quoted strings when you don't need " +
        'string interpolation or special symbols.'

      def on_str(node)
        text, = *node

        # Constants like __FILE__ and __DIR__ are created as strings,
        # but don't respond to begin.
        return unless node.loc.respond_to?(:begin)

        if text !~ /['\n\t\r]/ && node.loc.begin.source == '"'
          add_offence(:convention, node.loc.line, MSG)
        end
      end

      alias_method :on_dstr, :ignore_node
      alias_method :on_regexp, :ignore_node
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.8.3 lib/rubocop/cop/string_literals.rb
rubocop-0.8.2 lib/rubocop/cop/string_literals.rb
rubocop-0.8.1 lib/rubocop/cop/string_literals.rb