Class: Rubocop::Cop::Encoding

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/encoding.rb

Constant Summary collapse

ERROR_MESSAGE =
'Missing encoding comment.'

Instance Attribute Summary

Attributes inherited from Cop

#correlations, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, #has_report?, inherited, #initialize

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#inspect(file, source, tokens, sexp) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/rubocop/cop/encoding.rb', line 8

def inspect(file, source, tokens, sexp)
  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, 1, ERROR_MESSAGE)
    end
  end
end