Class: Rubocop::Cop::Style::Encoding
- Defined in:
- lib/rubocop/cop/style/encoding.rb
Overview
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.
Constant Summary collapse
- MSG =
'Missing utf-8 encoding comment.'
Instance Attribute Summary
Attributes inherited from Cop
#autocorrect, #debug, #disabled_lines, #offences
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, #autocorrect_action, cop_name, cop_type, #do_autocorrect, #ignore_node, inherited, #initialize, lint?, #name, rails?, style?
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#inspect(source_buffer, source, tokens, ast, comments) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rubocop/cop/style/encoding.rb', line 13 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 |