Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CheckingVisitor#warnings returns all checkers' warnings

  • Loading branch information...
commit 9911bfdc46a7cdd4ecfb1693e6bde14fd2ca31c4 1 parent fad8fba
@flyerhzm authored
View
1  lib/code_analyzer/checking_visitor.rb
@@ -1,6 +1,7 @@
# encoding: utf-8
module CodeAnalyzer
module CheckingVisitor
+ autoload :Base, "code_analyzer/checking_visitor/base"
autoload :Plain, "code_analyzer/checking_visitor/plain"
autoload :Default, "code_analyzer/checking_visitor/default"
end
View
15 lib/code_analyzer/checking_visitor/base.rb
@@ -0,0 +1,15 @@
+# encoding: utf-8
+module CodeAnalyzer::CheckingVisitor
+ # Base class for checking visitor.
+ class Base
+ def initialize(options={})
+ @checkers = options[:checkers]
+ end
+
+ def after_check; end
+
+ def warnings
+ @warnings ||= @checkers.map(&:warnings).flatten
+ end
+ end
+end
View
6 lib/code_analyzer/checking_visitor/default.rb
@@ -1,10 +1,10 @@
# encoding: utf-8
module CodeAnalyzer::CheckingVisitor
# This is the default checking visitor to check ruby sexp nodes.
- class Default
+ class Default < Base
def initialize(options={})
+ super
@checks = {}
- @checkers = options[:checkers]
@checkers.each do |checker|
checker.interesting_nodes.each do |node|
@checks[node] ||= []
@@ -12,7 +12,7 @@ def initialize(options={})
@checks[node].uniq!
end
end
- end
+ end
# check the ruby sexp nodes for the ruby file.
#
View
9 lib/code_analyzer/checking_visitor/plain.rb
@@ -1,11 +1,7 @@
# encoding: utf-8
module CodeAnalyzer::CheckingVisitor
# This is the checking visitor to check ruby plain code.
- class Plain
- def initialize(options={})
- @checkers = options[:checkers]
- end
-
+ class Plain < Base
# check the ruby plain code.
#
# @param [String] filename is the filename of ruby code.
@@ -15,8 +11,5 @@ def check(filename, content)
checker.check(filename, content)
end
end
-
- def after_check
- end
end
end
View
16 spec/code_analyzer/checking_visitor/base_spec.rb
@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+module CodeAnalyzer
+ module CheckingVisitor
+ describe Base do
+ it "should return all checkers' warnings" do
+ warning1 = Warning.new
+ checker1 = mock(:checker, warnings: [warning1])
+ warning2 = Warning.new
+ checker2 = mock(:checker, warnings: [warning2])
+ visitor = Base.new(checkers: [checker1, checker2])
+ visitor.warnings.should == [warning1, warning2]
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.