class JRuby::Lint::Collector

Attributes

checkers[RW]
contents[RW]
file[RW]
findings[RW]
project[RW]
stack[RW]

Public Class Methods

all() click to toggle source
# File lib/jruby/lint/collectors.rb, line 77
def self.all
  @collectors ||= []
end
inherited(base) click to toggle source
# File lib/jruby/lint/collectors.rb, line 73
def self.inherited(base)
  self.all << base
end
new(project = nil, file = nil) click to toggle source
# File lib/jruby/lint/collectors.rb, line 5
def initialize(project = nil, file = nil)
  @checkers = Checker.loaded_checkers.map(&:new)
  @checkers.each {|c| c.collector = self }
  @findings = []
  @project, @file = project, file || '<inline-script>'

  # top to bottom list of elements as they are visited
  @stack = [] # FIXME: ast visiting is not something checkers can see so stored here for now
end

Public Instance Methods

add_finding(message, tags, line=nil) click to toggle source
# File lib/jruby/lint/collectors.rb, line 15
def add_finding(message, tags, line=nil)
  src_line = line ? contents.split(/\n/)[line-1] : nil
  @findings << Finding.new(message, tags, file, line, src_line)
end
ast() click to toggle source
# File lib/jruby/lint/collectors.rb, line 65
def ast
  @ast ||= JRuby.parse(contents, file, true)
end
run() click to toggle source
# File lib/jruby/lint/collectors.rb, line 56
def run
  begin
    CheckersVisitor.new(ast, self, checkers).traverse
  rescue SyntaxError => e
    file, line, message = e.message.split(/:\s*/, 3)
    add_finding(message, [:syntax, :error], line.to_i)
  end
end