Class: CodeAnalyzer::Checker
- Inherits:
-
Object
- Object
- CodeAnalyzer::Checker
- Defined in:
- lib/code_analyzer/checker.rb
Overview
A checker class that takes charge of checking the sexp.
Class Method Summary collapse
- .add_callback(*names, &block) ⇒ Object
- .callbacks ⇒ Object
- .get_callbacks(name) ⇒ Object
- .interesting_files(*file_patterns) ⇒ Object
- .interesting_nodes(*nodes) ⇒ Object
Instance Method Summary collapse
-
#add_warning(message, filename = @node.file, line_number = @node.line) ⇒ Object
add an warning.
-
#interesting_files ⇒ Object
interesting files that the check will parse.
-
#interesting_nodes ⇒ Object
interesting nodes that the check will parse.
-
#node_end(node) ⇒ Object
delegate to end_### according to the sexp_type, like.
-
#node_start(node) ⇒ Object
delegate to start_### according to the sexp_type, like.
-
#parse_file?(node_file) ⇒ Boolean
check if the checker will parse the node file.
-
#warnings ⇒ Object
all warnings.
Class Method Details
.add_callback(*names, &block) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/code_analyzer/checker.rb', line 79 def add_callback(*names, &block) names.each do |name| callbacks[name] ||= [] callbacks[name] << block end end |
.callbacks ⇒ Object
86 87 88 |
# File 'lib/code_analyzer/checker.rb', line 86 def callbacks @callbacks ||= {} end |
.get_callbacks(name) ⇒ Object
74 75 76 77 |
# File 'lib/code_analyzer/checker.rb', line 74 def get_callbacks(name) callbacks[name] ||= [] callbacks[name] end |
.interesting_files(*file_patterns) ⇒ Object
69 70 71 72 |
# File 'lib/code_analyzer/checker.rb', line 69 def interesting_files(*file_patterns) @interesting_files ||= [] @interesting_files += file_patterns end |
.interesting_nodes(*nodes) ⇒ Object
64 65 66 67 |
# File 'lib/code_analyzer/checker.rb', line 64 def interesting_nodes(*nodes) @interesting_nodes ||= [] @interesting_nodes += nodes end |
Instance Method Details
#add_warning(message, filename = @node.file, line_number = @node.line) ⇒ Object
add an warning.
54 55 56 |
# File 'lib/code_analyzer/checker.rb', line 54 def add_warning(, filename = @node.file, line_number = @node.line) warnings << Warning.new(filename: filename, line_number: line_number, message: ) end |
#interesting_files ⇒ Object
interesting files that the check will parse.
11 12 13 |
# File 'lib/code_analyzer/checker.rb', line 11 def interesting_files self.class.interesting_files end |
#interesting_nodes ⇒ Object
interesting nodes that the check will parse.
6 7 8 |
# File 'lib/code_analyzer/checker.rb', line 6 def interesting_nodes self.class.interesting_nodes end |
#node_end(node) ⇒ Object
delegate to end_### according to the sexp_type, like
end_call
end_def
42 43 44 45 46 47 |
# File 'lib/code_analyzer/checker.rb', line 42 def node_end(node) @node = node self.class.get_callbacks("end_#{node.sexp_type}".to_sym).each do |block| self.instance_exec(node, &block) end end |
#node_start(node) ⇒ Object
delegate to start_### according to the sexp_type, like
start_call
start_def
29 30 31 32 33 34 |
# File 'lib/code_analyzer/checker.rb', line 29 def node_start(node) @node = node self.class.get_callbacks("start_#{node.sexp_type}".to_sym).each do |block| self.instance_exec(node, &block) end end |
#parse_file?(node_file) ⇒ Boolean
check if the checker will parse the node file.
19 20 21 |
# File 'lib/code_analyzer/checker.rb', line 19 def parse_file?(node_file) interesting_files.any? { |pattern| node_file =~ pattern } end |
#warnings ⇒ Object
all warnings.
59 60 61 |
# File 'lib/code_analyzer/checker.rb', line 59 def warnings @warnings ||= [] end |