Class: JRuby::Lint::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/jruby/lint/collectors.rb

Defined Under Namespace

Classes: CheckersVisitor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project = nil, file = nil) ⇒ Collector

Returns a new instance of Collector.



5
6
7
8
9
10
# 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>'
end

Instance Attribute Details

#checkersObject

Returns the value of attribute checkers.



3
4
5
# File 'lib/jruby/lint/collectors.rb', line 3

def checkers
  @checkers
end

#contentsObject

Returns the value of attribute contents.



3
4
5
# File 'lib/jruby/lint/collectors.rb', line 3

def contents
  @contents
end

#fileObject

Returns the value of attribute file.



3
4
5
# File 'lib/jruby/lint/collectors.rb', line 3

def file
  @file
end

#findingsObject

Returns the value of attribute findings.



3
4
5
# File 'lib/jruby/lint/collectors.rb', line 3

def findings
  @findings
end

#projectObject

Returns the value of attribute project.



3
4
5
# File 'lib/jruby/lint/collectors.rb', line 3

def project
  @project
end

Class Method Details

.allObject



66
67
68
# File 'lib/jruby/lint/collectors.rb', line 66

def self.all
  @collectors ||= []
end

.inherited(base) ⇒ Object



62
63
64
# File 'lib/jruby/lint/collectors.rb', line 62

def self.inherited(base)
  self.all << base
end

Instance Method Details

#astObject



54
55
56
# File 'lib/jruby/lint/collectors.rb', line 54

def ast
  @ast ||= JRuby.parse(contents, file, true)
end

#runObject



45
46
47
48
49
50
51
52
# File 'lib/jruby/lint/collectors.rb', line 45

def run
  begin
    CheckersVisitor.new(ast, self, checkers).traverse
  rescue SyntaxError => e
    file, line, message = e.message.split(/:\s*/, 3)
    findings << Finding.new(message, [:syntax, :error], file, line)
  end
end