-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bozhidar Batsov
committed
May 15, 2013
1 parent
1ec8996
commit 01fda72
Showing
1 changed file
with
10 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bbatsov
Collaborator
|
||
add_offence(:convention, | ||
s.src.line, | ||
ERROR_MESSAGE) | ||
end | ||
end | ||
end | ||
end | ||
|
I think I've been planning to add a
.src.dot
accessor.This code will fail at e.g.
foo(Bar::Baz)
.