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

Class Method 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.



18
19
20
21
22
23
24
25
# File 'lib/rubocop/cop/commissioner.rb', line 18

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

Class Method Details

.callback_methodsObject



14
15
16
# File 'lib/rubocop/cop/commissioner.rb', line 14

def self.callback_methods
  Parser::Meta::NODE_TYPES.map { |type| :"on_#{type}" }
end

Instance Method Details

#investigate(processed_source) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/rubocop/cop/commissioner.rb', line 53

def investigate(processed_source)
  reset_errors
  remove_irrelevant_cops(processed_source.buffer.name)
  reset_callbacks
  prepare(processed_source)
  invoke_custom_processing(@cops, processed_source)
  invoke_custom_processing(@forces, processed_source)
  walk(processed_source.ast) if processed_source.ast
  @cops.flat_map(&:offenses)
end