Class: Templatecop::RubyOffenseCollector

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

Overview

Collect RuboCop offenses from Ruby code.

Instance Method Summary collapse

Constructor Details

#initialize(autocorrect:, file_path:, rubocop_config:, source:, debug: false) ⇒ RubyOffenseCollector

Returns a new instance of RubyOffenseCollector.

Parameters:

  • autocorrect (Boolean)
  • debug (Boolean) (defaults to: false)
  • file_path (String)
  • rubocop_config (RuboCop::Config)
  • source (String)


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

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

Instance Method Details

#callArray<RuboCop::Cop::Offense>

Returns:

  • (Array<RuboCop::Cop::Offense>)


28
29
30
31
32
33
# File 'lib/templatecop/ruby_offense_collector.rb', line 28

def call
  # Skip if invalid syntax Ruby code is given. (e.g. "- if a?")
  return [] unless rubocop_processed_source.valid_syntax?

  rubocop_team.investigate(rubocop_processed_source).offenses.reject(&:disabled?)
end