Class: RuboCop::Cop::Commissioner
- Inherits:
-
Parser::AST::Processor
- Object
- Parser::AST::Processor
- RuboCop::Cop::Commissioner
- Defined in:
- lib/rubocop/cop/commissioner.rb
Overview
Commissioner class is responsible for processing the AST and delegating work to the specified cops.
Constant Summary collapse
- METHODS_NOT_DEFINED_IN_PARSER_PROCESSOR =
[ :on_sym, :on_str, :on_int, :on_float ]
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Class Method Summary collapse
-
.call_super(callback) ⇒ Object
Methods that are not defined in Parser::AST::Processor won't have a
super
to call. - .callback_methods ⇒ Object
Instance Method Summary collapse
-
#initialize(cops, forces, options = {}) ⇒ Commissioner
constructor
A new instance of Commissioner.
- #investigate(processed_source) ⇒ Object
Constructor Details
#initialize(cops, forces, options = {}) ⇒ Commissioner
Returns a new instance of Commissioner.
31 32 33 34 35 36 |
# File 'lib/rubocop/cop/commissioner.rb', line 31 def initialize(cops, forces, = {}) @cops = cops @forces = forces @options = reset_errors end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/rubocop/cop/commissioner.rb', line 8 def errors @errors end |
Class Method Details
.call_super(callback) ⇒ Object
Methods that are not defined in Parser::AST::Processor
won't have a super
to call. So we should not attempt
to invoke super
when defining them.
23 24 25 26 27 28 29 |
# File 'lib/rubocop/cop/commissioner.rb', line 23 def self.call_super(callback) if METHODS_NOT_DEFINED_IN_PARSER_PROCESSOR.include?(callback) '' else 'super' end end |
.callback_methods ⇒ Object
14 15 16 17 18 |
# File 'lib/rubocop/cop/commissioner.rb', line 14 def self.callback_methods Parser::AST::Processor.instance_methods.select do |method| method.to_s =~ /^on_/ end + METHODS_NOT_DEFINED_IN_PARSER_PROCESSOR end |
Instance Method Details
#investigate(processed_source) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rubocop/cop/commissioner.rb', line 53 def investigate(processed_source) reset_errors prepare(processed_source) invoke_custom_processing(@cops, processed_source) invoke_custom_processing(@forces, processed_source) process(processed_source.ast) if processed_source.ast @cops.each_with_object([]) do |cop, offenses| filename = processed_source.buffer.name # ignore files that are of no interest to the cop in question offenses.concat(cop.offenses) if cop.relevant_file?(filename) end end |