Class: Rubocop::Cop::Team
- Inherits:
-
Object
- Object
- Rubocop::Cop::Team
- Defined in:
- lib/rubocop/cop/team.rb
Overview
FIXME
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #autocorrect? ⇒ Boolean
- #cops ⇒ Object
- #debug? ⇒ Boolean
-
#initialize(cop_classes, config, options = nil) ⇒ Team
constructor
A new instance of Team.
- #inspect_file(file) ⇒ Object
Constructor Details
#initialize(cop_classes, config, options = nil) ⇒ Team
Returns a new instance of Team.
9 10 11 12 13 14 |
# File 'lib/rubocop/cop/team.rb', line 9 def initialize(cop_classes, config, = nil) @cop_classes = cop_classes @config = config @options = || { autocorrect: false, debug: false } @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/rubocop/cop/team.rb', line 7 def errors @errors end |
Instance Method Details
#autocorrect? ⇒ Boolean
16 17 18 |
# File 'lib/rubocop/cop/team.rb', line 16 def autocorrect? @options[:autocorrect] end |
#cops ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/rubocop/cop/team.rb', line 51 def cops @cops ||= begin @cop_classes.reduce([]) do |instances, cop_class| next instances unless @config.cop_enabled?(cop_class) instances << cop_class.new(@config, @options) end end end |
#debug? ⇒ Boolean
20 21 22 |
# File 'lib/rubocop/cop/team.rb', line 20 def debug? @options[:debug] end |
#inspect_file(file) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rubocop/cop/team.rb', line 24 def inspect_file(file) begin processed_source = SourceParser.parse_file(file) rescue Encoding::UndefinedConversionError, ArgumentError => e handle_error(e, "An error occurred while parsing #{file}.".color(:red)) return [] end offences = processed_source.diagnostics.map do |diagnostic| Offence.from_diagnostic(diagnostic) end # If we got any syntax errors, return only the syntax offences. # Parser may return nil for AST even though there are no syntax errors. # e.g. sources which contain only comments if offences.any? { |o| [:error, :fatal].include?(o.severity) } return offences end commissioner = Commissioner.new(cops) offences += commissioner.investigate(processed_source) process_commissioner_errors(file, commissioner.errors) autocorrect(processed_source.buffer, cops) offences.sort end |