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 = || { auto_correct: 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[:auto_correct] end |
#cops ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/rubocop/cop/team.rb', line 48 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 |
# File 'lib/rubocop/cop/team.rb', line 24 def inspect_file(file) begin processed_source = SourceParser.parse_file(file) rescue Encoding::UndefinedConversionError, ArgumentError => e range = Struct.new(:line, :column, :source_line).new(1, 0, '') return [Offence.new(:fatal, range, e..capitalize + '.', 'Parser')] 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 unless processed_source.valid_syntax? diagnostics = processed_source.diagnostics return Lint::Syntax.offences_from_diagnostics(diagnostics) end commissioner = Commissioner.new(cops) offences = commissioner.investigate(processed_source) process_commissioner_errors(file, commissioner.errors) autocorrect(processed_source.buffer, cops) offences.sort end |