Class: Rubocop::Cop::ColonMethodCall

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

Constant Summary collapse

ERROR_MESSAGE =
'Do not use :: for method invocation.'

Instance Attribute Summary

Attributes inherited from Cop

#correlations, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

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

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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubocop/cop/colon_method_call.rb', line 8

def inspect(file, source, tokens, sexp)
  state = :outside
  tokens.each do |t|
    state = case [state, t.type]
            when [:outside, :on_const]
              :const

            when [:outside, :on_ident]
              :ident

            when [:const, :on_op]
              t.text == '::' ? :const_colon : :outside

            when [:ident, :on_op]
              t.text == '::' ? :ident_colon : :outside

            when [:ident_colon, :on_ident]
              add_offence(:convention, t.pos.lineno, ERROR_MESSAGE)
              :ident

            when [:const_colon, :on_ident]
              add_offence(:convention, t.pos.lineno, ERROR_MESSAGE)
              :ident

            when [:ident_colon, :on_const]
              :const

            when [:const_colon, :on_const]
              :const
            else
              :outside
      end || state
  end
end