Class: RuboCounsel::Runner

Inherits:
RuboCop::Runner
  • Object
show all
Defined in:
lib/rubocounsel/runner.rb

Overview

Subclass of RuboCop::Runner that tracks which cops fired offenses.

Responsibilities:

- Run RuboCop normally
- Hook file_finished to track offending cop names
- Provide the list of offending cops to the Counselor

The runner separates the concern of "run RuboCop and collect offenses" from the interactive CLI experience (handled by Counselor).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rubocop_options: {}) ⇒ Runner

Returns a new instance of Runner.



18
19
20
21
22
23
24
25
26
27
# File 'lib/rubocounsel/runner.rb', line 18

def initialize(rubocop_options: {})
  @offending_cops = Set.new

  options = rubocop_options.merge(formatters: [])

  config_store = RuboCop::ConfigStore.new
  config_store.options_config = options[:config] if options[:config]

  super(options, config_store)
end

Instance Attribute Details

#offending_copsObject (readonly)

Returns the value of attribute offending_cops.



16
17
18
# File 'lib/rubocounsel/runner.rb', line 16

def offending_cops
  @offending_cops
end

Instance Method Details

#file_finished(_file, offenses) ⇒ Object



29
30
31
32
# File 'lib/rubocounsel/runner.rb', line 29

def file_finished(_file, offenses)
  @offending_cops.merge(offenses.map(&:cop_name)) unless offenses.empty?
  super
end