lib/rubocop/cop/cop.rb in rubocop-0.5.0 vs lib/rubocop/cop/cop.rb in rubocop-0.6.0

- old
+ new

@@ -30,11 +30,11 @@ end end class Cop attr_accessor :offences - attr_writer :correlations + attr_writer :correlations, :disabled_lines @all = [] @config = {} class << self @@ -53,11 +53,13 @@ def has_report? !@offences.empty? end def add_offence(severity, line_number, message) - @offences << Offence.new(severity, line_number, message) + unless @disabled_lines && @disabled_lines.include?(line_number) + @offences << Offence.new(severity, line_number, message) + end end private def each_parent_of(sym, sexp) @@ -81,16 +83,26 @@ sexp.each do |elem| each(sym, elem) { |s| yield s } if Array === elem end end + def find_all(sym, sexp) + result = [] + each(sym, sexp) { |s| result << s } + result + end + + def find_first(sym, sexp) + find_all(sym, sexp).first + end + def whitespace?(token) [:on_sp, :on_ignored_nl, :on_nl].include?(token.type) end def all_positions(sexp) return [sexp[2]] if sexp[0] =~ /^@/ - sexp.grep(Array).reduce([]) { |memo, s| memo + all_positions(s) } + sexp.grep(Array).reduce([]) { |a, e| a + all_positions(e) } end end end end