Class: RuboCop::Cop::Team

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/team.rb

Overview

FIXME

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cop_classes, config, options = nil) ⇒ Team

Returns a new instance of Team.



11
12
13
14
15
16
17
# File 'lib/rubocop/cop/team.rb', line 11

def initialize(cop_classes, config, options = nil)
  @cop_classes = cop_classes
  @config = config
  @options = options || { auto_correct: false, debug: false }
  @errors = []
  @warnings = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/rubocop/cop/team.rb', line 7

def errors
  @errors
end

#updated_source_fileObject (readonly) Also known as: updated_source_file?

Returns the value of attribute updated_source_file.



7
8
9
# File 'lib/rubocop/cop/team.rb', line 7

def updated_source_file
  @updated_source_file
end

#warningsObject (readonly)

Returns the value of attribute warnings.



7
8
9
# File 'lib/rubocop/cop/team.rb', line 7

def warnings
  @warnings
end

Instance Method Details

#autocorrect?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rubocop/cop/team.rb', line 19

def autocorrect?
  @options[:auto_correct]
end

#copsObject



40
41
42
43
44
45
# File 'lib/rubocop/cop/team.rb', line 40

def cops
  @cops ||= @cop_classes.each_with_object([]) do |cop_class, instances|
    next unless cop_enabled?(cop_class)
    instances << cop_class.new(@config, @options)
  end
end

#debug?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rubocop/cop/team.rb', line 23

def debug?
  @options[:debug]
end

#forcesObject



47
48
49
50
51
52
53
# File 'lib/rubocop/cop/team.rb', line 47

def forces
  @forces ||= 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



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rubocop/cop/team.rb', line 27

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

  commissioner = Commissioner.new(cops, forces)
  offenses = commissioner.investigate(processed_source)
  process_commissioner_errors(processed_source.path, commissioner.errors)
  autocorrect(processed_source.buffer, cops)
  offenses
end