class CodeAnalyzer::Checker

A checker class that takes charge of checking the sexp.

Public Class Methods

add_callback(*names, &block) click to toggle source
# File lib/code_analyzer/checker.rb, line 76
def add_callback(*names, &block)
  names.each do |name|
    callbacks[name] ||= []
    callbacks[name] << block
  end
end
callbacks() click to toggle source
# File lib/code_analyzer/checker.rb, line 83
def callbacks
  @callbacks ||= {}
end
get_callbacks(name) click to toggle source
# File lib/code_analyzer/checker.rb, line 71
def get_callbacks(name)
  callbacks[name] ||= []
  callbacks[name]
end
interesting_files(*file_patterns) click to toggle source
# File lib/code_analyzer/checker.rb, line 66
def interesting_files(*file_patterns)
  @interesting_files ||= []
  @interesting_files += file_patterns
end
interesting_nodes(*nodes) click to toggle source
# File lib/code_analyzer/checker.rb, line 61
def interesting_nodes(*nodes)
  @interesting_nodes ||= []
  @interesting_nodes += nodes
end

Public Instance Methods

add_warning(message, filename = @node.file, line_number = @node.line_number) click to toggle source

add an warning.

@param [String] message, is the warning message @param [String] filename, is the filename of source code @param [Integer] line_number, is the line number of the source code which is reviewing

# File lib/code_analyzer/checker.rb, line 51
def add_warning(message, filename = @node.file, line_number = @node.line_number)
  warnings << Warning.new(filename: filename, line_number: line_number, message: message)
end
interesting_files() click to toggle source

interesting files that the check will parse.

# File lib/code_analyzer/checker.rb, line 12
def interesting_files
  self.class.interesting_files
end
interesting_nodes() click to toggle source

interesting nodes that the check will parse.

# File lib/code_analyzer/checker.rb, line 7
def interesting_nodes
  self.class.interesting_nodes
end
node_end(node) click to toggle source

delegate to end_### according to the sexp_type, like

end_call
end_def

@param [Sexp] node

# File lib/code_analyzer/checker.rb, line 41
def node_end(node)
  @node = node
  self.class.get_callbacks("end_#{node.sexp_type}".to_sym).each { |block| self.instance_exec(node, &block) }
end
node_start(node) click to toggle source

delegate to start_### according to the sexp_type, like

start_call
start_def

@param [Sexp] node

# File lib/code_analyzer/checker.rb, line 30
def node_start(node)
  @node = node
  self.class.get_callbacks("start_#{node.sexp_type}".to_sym).each { |block| self.instance_exec(node, &block) }
end
parse_file?(node_file) click to toggle source

check if the checker will parse the node file.

@param [String] the file name of node. @return [Boolean] true if the checker will parse the file.

# File lib/code_analyzer/checker.rb, line 20
def parse_file?(node_file)
  interesting_files.any? { |pattern| node_file =~ pattern }
end
warnings() click to toggle source

all warnings.

# File lib/code_analyzer/checker.rb, line 56
def warnings
  @warnings ||= []
end