Skip to content

Commit

Permalink
Port ColonMethodCall to Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Bozhidar Batsov committed May 15, 2013
1 parent 1ec8996 commit 01fda72
Showing 1 changed file with 10 additions and 31 deletions.
41 changes: 10 additions & 31 deletions lib/rubocop/cop/colon_method_call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,17 @@ module Cop
class ColonMethodCall < Cop
ERROR_MESSAGE = 'Do not use :: for method invocation.'

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
def self.portable?
true
end

when [:const_colon, :on_const]
:const
else
:outside
end || state
def inspect(file, source, tokens, sexp)
on_node(:send, sexp) do |s|
if s.src.expression.to_source.include?('::')

This comment has been minimized.

Copy link
@whitequark

whitequark May 15, 2013

I think I've been planning to add a .src.dot accessor.

This code will fail at e.g. foo(Bar::Baz).

This comment has been minimized.

Copy link
@bbatsov

bbatsov May 16, 2013

Collaborator

Yep, I've noticed that right after I wrote the code and refactored it a bit.

I was planning to propose the addition of .src.dot myself after having to deal with this case. I'll create a ticket for that.

add_offence(:convention,
s.src.line,
ERROR_MESSAGE)
end
end
end
end
Expand Down

0 comments on commit 01fda72

Please sign in to comment.