Class: Pronto::Rubocop::PatchCop

Inherits:
Object
  • Object
show all
Defined in:
lib/pronto/rubocop/patch_cop.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patch, runner) ⇒ PatchCop

Returns a new instance of PatchCop.



8
9
10
11
# File 'lib/pronto/rubocop/patch_cop.rb', line 8

def initialize(patch, runner)
  @patch = patch
  @runner = runner
end

Instance Attribute Details

#runnerObject (readonly)

Returns the value of attribute runner.



6
7
8
# File 'lib/pronto/rubocop/patch_cop.rb', line 6

def runner
  @runner
end

Instance Method Details

#messagesObject



13
14
15
16
17
18
19
# File 'lib/pronto/rubocop/patch_cop.rb', line 13

def messages
  return [] unless valid?

  offenses
    .map { |offense| first_relevant_message(patch, offense) }
    .compact
end

#processed_sourceObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pronto/rubocop/patch_cop.rb', line 21

def processed_source
  @processed_source ||= begin
    processed_source = ::RuboCop::ProcessedSource.from_file(
      path,
      rubocop_config.target_ruby_version
    )
    processed_source.registry = registry if processed_source.respond_to?(:registry=)
    processed_source.config = rubocop_config if processed_source.respond_to?(:config=)
    processed_source
  end
end

#registryObject



33
34
35
# File 'lib/pronto/rubocop/patch_cop.rb', line 33

def registry
  @registry ||= ::RuboCop::Cop::Registry.new(RuboCop::Cop::Cop.all)
end

#rubocop_configObject



37
38
39
40
41
42
43
# File 'lib/pronto/rubocop/patch_cop.rb', line 37

def rubocop_config
  @rubocop_config ||= begin
    store = ::RuboCop::ConfigStore.new
    store.options_config = ENV['RUBOCOP_CONFIG'] if ENV['RUBOCOP_CONFIG']
    store.for(path)
  end
end