Class: Rubocop::Cop::Encoding

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

Constant Summary collapse

ERROR_MESSAGE =
'Missing encoding comment.'
MAX_LINE_LENGTH =
80

Instance Attribute Summary

Attributes inherited from Cop

#offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, enabled?, #has_report?, inherited, #initialize, #inspect_source

Constructor Details

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

Instance Method Details

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



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

def inspect(file, source, tokens, sexp)
  unless source[0] =~ /#.*coding: (UTF|utf)-8/
    message = sprintf(ERROR_MESSAGE)
    add_offence(:convention, 0, 0, message)
  end
end