Class: RuboCop::Cop::Commissioner

Inherits:
Object
  • Object
show all
Includes:
AST::Traversal
Defined in:
lib/rubocop/cop/commissioner.rb

Overview

Commissioner class is responsible for processing the AST and delegating work to the specified cops.

Defined Under Namespace

Classes: CopError

Constant Summary

Constants included from AST::Traversal

AST::Traversal::MANY_CHILD_NODES, AST::Traversal::NO_CHILD_NODES, AST::Traversal::ONE_CHILD_NODE, AST::Traversal::SECOND_CHILD_ONLY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AST::Traversal

#on_block, #on_case, #on_casgn, #on_class, #on_const, #on_def, #on_defs, #on_if, #on_op_asgn, #on_send, #on_while, #walk

Constructor Details

#initialize(cops, forces = [], options = {}) ⇒ Commissioner

Returns a new instance of Commissioner



14
15
16
17
18
19
20
21
# File 'lib/rubocop/cop/commissioner.rb', line 14

def initialize(cops, forces = [], options = {})
  @cops = cops
  @forces = forces
  @options = options
  @callbacks = {}

  reset_errors
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors



12
13
14
# File 'lib/rubocop/cop/commissioner.rb', line 12

def errors
  @errors
end

Instance Method Details

#investigate(processed_source) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rubocop/cop/commissioner.rb', line 39

def investigate(processed_source)
  reset_errors
  remove_irrelevant_cops(processed_source.file_path)
  reset_callbacks
  prepare(processed_source)
  invoke_custom_processing(@cops, processed_source)
  invoke_custom_processing(@forces, processed_source)
  walk(processed_source.ast) unless processed_source.blank?
  invoke_custom_post_walk_processing(@cops, processed_source)
  @cops.flat_map(&:offenses)
end