Class: Rubocop::Cop::HashSyntax

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

Constant Summary collapse

MSG =
'Ruby 1.8 hash syntax detected'

Instance Attribute Summary

Attributes inherited from Cop

#debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, cop_name, #has_report?, inherited, #initialize, #inspect, #name, #on_comment

Constructor Details

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

Instance Method Details

#on_hash(node) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rubocop/cop/hash_syntax.rb', line 8

def on_hash(node)
  pairs = *node

  sym_indices = pairs.all? { |p| word_symbol_pair?(p) }

  if sym_indices
    pairs.each do |pair|
      if pair.loc.operator && pair.loc.operator.source == '=>'
        add_offence(:convention,
                    pair.loc.line,
                    MSG)
      end
    end
  end

  super
end