Sha256: 66101f0e8d1e3ff9066e4b5380a3d195ef4651fabb0e142e2c6725be3379cba9

Contents?: true

Size: 626 Bytes

Versions: 5

Compression:

Stored size: 626 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class PercentLiterals < Cop
      ERROR_MESSAGE = 'The use of %s is discouraged.'
      BAD_LITERALS = {
        on_tstring_beg: '%q',
        on_symbeg: '%s',
        on_backtick: '%x'
      }

      def inspect(file, source, tokens, sexp)
        tokens.each_index do |ix|
          t = tokens[ix]
          bad_token = BAD_LITERALS[t.type]
          if bad_token && t.text.downcase.start_with?(bad_token)
            add_offence(:convention, t.pos.lineno,
                        sprintf(ERROR_MESSAGE, t.text[0, 2]))
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-0.7.2 lib/rubocop/cop/percent_literals.rb
rubocop-0.7.1 lib/rubocop/cop/percent_literals.rb
rubocop-0.7.0 lib/rubocop/cop/percent_literals.rb
rubocop-0.6.1 lib/rubocop/cop/percent_literals.rb
rubocop-0.6.0 lib/rubocop/cop/percent_literals.rb