lib/rubocop/cop/cop.rb in rubocop-0.7.1 vs lib/rubocop/cop/cop.rb in rubocop-0.7.2

- old
+ new

@@ -114,20 +114,20 @@ return [sexp[2]] if sexp[0] =~ /^@/ sexp.grep(Array).reduce([]) { |a, e| a + all_positions(e) } end def keywords(tokens) - # we need to keep track of the previous token to avoid - # interpreting :some_keyword as the keyword some_keyword + # We need to keep track of the previous token to avoid + # interpreting :some_keyword as the keyword some_keyword. prev = Token.new(0, :init, '') - # same goes for defs so we need to track those as well + # Same goes for defs so we need to track those as well. keywords = [] - tokens.each do |t| - keywords << t if prev.type != :on_symbeg && t.type == :on_kw - # def with name that's a kw confuses Ripper.lex - penultimate = keywords[-2] - keywords.pop if penultimate && penultimate.text == 'def' + tokens.reject { |t| whitespace?(t) }.each do |t| + if prev.type != :on_symbeg && t.type == :on_kw && + [prev.type, prev.text] != [:on_kw, 'def'] + keywords << t + end prev = t end keywords end