Sha256: 8f8f4a6911fca4d338fb34a8ad7f5aeddb58eee7f92670797119d74ca7b49478

Contents?: true

Size: 917 Bytes

Versions: 3

Compression:

Stored size: 917 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # This cop checks whether the source file has a
      # utf-8 encoding comment. This check makes sense only
      # in Ruby 1.9, since in 2.0+ utf-8 is the default source file
      # encoding.
      class Encoding < Cop
        MSG = 'Missing utf-8 encoding comment.'

        def inspect(source_buffer, source, tokens, ast, comments)
          unless RUBY_VERSION >= '2.0.0'
            expected_line = 0
            expected_line += 1 if source[expected_line] =~ /^#!/
            unless source[expected_line] =~ /#.*coding: (UTF|utf)-8/
              add_offence(:convention,
                          source_range(source_buffer,
                                       source[0...expected_line],
                                       0, 1),
                          MSG)
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
rubocop-0.9.1 lib/rubocop/cop/style/encoding.rb
sabat-rubocop-0.9.0 lib/rubocop/cop/style/encoding.rb
rubocop-0.9.0 lib/rubocop/cop/style/encoding.rb