Class: Templatecop::TemplateOffenseCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/templatecop/template_offense_collector.rb

Overview

Collect RuboCop offenses from Template code.

Instance Method Summary collapse

Constructor Details

#initialize(autocorrect:, debug:, file_path:, rubocop_config:, ruby_extractor:, source:) ⇒ TemplateOffenseCollector

Returns a new instance of TemplateOffenseCollector.

Parameters:

  • autocorrect (Boolean)
  • debug (Boolean)
  • file_path (String)

    Template file path

  • rubocop_config (RuboCop::Config)
  • ruby_extractor (#call)
  • source (String)

    Template code



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/templatecop/template_offense_collector.rb', line 12

def initialize(
  autocorrect:,
  debug:,
  file_path:,
  rubocop_config:,
  ruby_extractor:,
  source:
)
  @autocorrect = autocorrect
  @debug = debug
  @file_path = file_path
  @rubocop_config = rubocop_config
  @ruby_extractor = ruby_extractor
  @source = source
end

Instance Method Details

#callArray<Templatecop::Offense>

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/templatecop/template_offense_collector.rb', line 29

def call
  snippets.flat_map do |snippet|
    RubyOffenseCollector.new(
      autocorrect: @autocorrect,
      debug: @debug,
      file_path: @file_path,
      rubocop_config: @rubocop_config,
      source: snippet[:code]
    ).call.map do |rubocop_offense|
      Offense.new(
        file_path: @file_path,
        offset: snippet[:offset],
        rubocop_offense: rubocop_offense,
        source: @source
      )
    end
  end
end