Class: RuboCop::Cop::Team
- Inherits:
-
Object
- Object
- RuboCop::Cop::Team
- Defined in:
- lib/rubocop/cop/team.rb
Overview
FIXME
Constant Summary collapse
- INCOMPATIBLE_COPS =
If these cops try to autocorrect the same file at the same time, bad things are liable to happen
{ Style::SymbolProc => [Style::SpaceBeforeBlockBraces], Style::SpaceBeforeBlockBraces => [Style::SymbolProc] }.freeze
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#updated_source_file ⇒ Object
(also: #updated_source_file?)
readonly
Returns the value of attribute updated_source_file.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
- #autocorrect? ⇒ Boolean
- #cops ⇒ Object
- #debug? ⇒ Boolean
- #forces ⇒ Object
- #forces_for(cops) ⇒ Object
-
#initialize(cop_classes, config, options = nil) ⇒ Team
constructor
A new instance of Team.
- #inspect_file(processed_source) ⇒ Object
Constructor Details
#initialize(cop_classes, config, options = nil) ⇒ Team
Returns a new instance of Team.
19 20 21 22 23 24 25 26 27 |
# File 'lib/rubocop/cop/team.rb', line 19 def initialize(cop_classes, config, = nil) @cop_classes = cop_classes @config = config @options = || { auto_correct: false, debug: false } @errors = [] @warnings = [] validate_config end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
15 16 17 |
# File 'lib/rubocop/cop/team.rb', line 15 def errors @errors end |
#updated_source_file ⇒ Object (readonly) Also known as: updated_source_file?
Returns the value of attribute updated_source_file.
15 16 17 |
# File 'lib/rubocop/cop/team.rb', line 15 def updated_source_file @updated_source_file end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
15 16 17 |
# File 'lib/rubocop/cop/team.rb', line 15 def warnings @warnings end |
Instance Method Details
#autocorrect? ⇒ Boolean
29 30 31 |
# File 'lib/rubocop/cop/team.rb', line 29 def autocorrect? @options[:auto_correct] end |
#cops ⇒ Object
71 72 73 74 75 |
# File 'lib/rubocop/cop/team.rb', line 71 def cops @cops ||= @cop_classes.select { |c| cop_enabled?(c) }.map do |cop_class| cop_class.new(@config, @options) end end |
#debug? ⇒ Boolean
33 34 35 |
# File 'lib/rubocop/cop/team.rb', line 33 def debug? @options[:debug] end |
#forces ⇒ Object
77 78 79 |
# File 'lib/rubocop/cop/team.rb', line 77 def forces @forces ||= forces_for(cops) end |
#forces_for(cops) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/rubocop/cop/team.rb', line 81 def forces_for(cops) Force.all.each_with_object([]) do |force_class, forces| joining_cops = cops.select { |cop| cop.join_force?(force_class) } next if joining_cops.empty? forces << force_class.new(joining_cops) end end |
#inspect_file(processed_source) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rubocop/cop/team.rb', line 37 def inspect_file(processed_source) # If we got any syntax errors, return only the syntax offenses. unless processed_source.valid_syntax? return Lint::Syntax.offenses_from_processed_source(processed_source) end # The autocorrection process may have to be repeated multiple times # until there are no corrections left to perform # To speed things up, run auto-correcting cops by themselves, and only # run the other cops when no corrections are left autocorrect_cops, other_cops = cops.partition(&:autocorrect?) offenses = [] errors = {} if autocorrect_cops.any? commissioner = Commissioner.new(autocorrect_cops, forces_for(autocorrect_cops)) offenses = commissioner.investigate(processed_source) if autocorrect(processed_source.buffer, autocorrect_cops) # We corrected some errors. Another round of inspection will be # done, and any other offenses will be caught then, so we don't # need to continue. return offenses end errors = commissioner.errors end commissioner = Commissioner.new(other_cops, forces_for(other_cops)) offenses.concat(commissioner.investigate(processed_source)) errors.merge!(commissioner.errors) process_commissioner_errors(processed_source.path, errors) offenses end |