Class: JRuby::Lint::Collector
- Inherits:
-
Object
- Object
- JRuby::Lint::Collector
- Defined in:
- lib/jruby/lint/collectors.rb
Direct Known Subclasses
JRuby::Lint::Collectors::Bundler, JRuby::Lint::Collectors::Gemspec, JRuby::Lint::Collectors::Rake, JRuby::Lint::Collectors::Ruby
Defined Under Namespace
Classes: CheckersVisitor
Instance Attribute Summary collapse
-
#checkers ⇒ Object
Returns the value of attribute checkers.
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#file ⇒ Object
Returns the value of attribute file.
-
#findings ⇒ Object
Returns the value of attribute findings.
-
#project ⇒ Object
Returns the value of attribute project.
-
#stack ⇒ Object
Returns the value of attribute stack.
Class Method Summary collapse
Instance Method Summary collapse
- #add_finding(message, tags, line = nil) ⇒ Object
- #ast ⇒ Object
-
#initialize(project = nil, file = nil) ⇒ Collector
constructor
A new instance of Collector.
- #run ⇒ Object
Constructor Details
#initialize(project = nil, file = nil) ⇒ Collector
Returns a new instance of Collector.
5 6 7 8 9 10 11 12 13 |
# 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 |
Instance Attribute Details
#checkers ⇒ Object
Returns the value of attribute checkers.
3 4 5 |
# File 'lib/jruby/lint/collectors.rb', line 3 def checkers @checkers end |
#contents ⇒ Object
Returns the value of attribute contents.
3 4 5 |
# File 'lib/jruby/lint/collectors.rb', line 3 def contents @contents end |
#file ⇒ Object
Returns the value of attribute file.
3 4 5 |
# File 'lib/jruby/lint/collectors.rb', line 3 def file @file end |
#findings ⇒ Object
Returns the value of attribute findings.
3 4 5 |
# File 'lib/jruby/lint/collectors.rb', line 3 def findings @findings end |
#project ⇒ Object
Returns the value of attribute project.
3 4 5 |
# File 'lib/jruby/lint/collectors.rb', line 3 def project @project end |
#stack ⇒ Object
Returns the value of attribute stack.
3 4 5 |
# File 'lib/jruby/lint/collectors.rb', line 3 def stack @stack end |
Class Method Details
.all ⇒ Object
77 78 79 |
# File 'lib/jruby/lint/collectors.rb', line 77 def self.all @collectors ||= [] end |
.inherited(base) ⇒ Object
73 74 75 |
# File 'lib/jruby/lint/collectors.rb', line 73 def self.inherited(base) self.all << base end |
Instance Method Details
#add_finding(message, tags, line = nil) ⇒ Object
15 16 17 18 |
# File 'lib/jruby/lint/collectors.rb', line 15 def add_finding(, , line=nil) src_line = line ? contents.split(/\n/)[line-1] : nil @findings << Finding.new(, , file, line, src_line) end |
#ast ⇒ Object
65 66 67 |
# File 'lib/jruby/lint/collectors.rb', line 65 def ast @ast ||= JRuby.parse(contents, file, true) end |
#run ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/jruby/lint/collectors.rb', line 56 def run begin CheckersVisitor.new(ast, self, checkers).traverse rescue SyntaxError => e file, line, = e..split(/:\s*/, 3) add_finding(, [:syntax, :error], line.to_i) end end |