Class: NdrDevSupport::Rubocop::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/ndr_dev_support/rubocop/executor.rb

Overview

This class filters the Rubocop report of a file to only the given lines.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filenames) ⇒ Executor

Returns a new instance of Executor.



16
17
18
# File 'lib/ndr_dev_support/rubocop/executor.rb', line 16

def initialize(filenames)
  @filenames = Executor.target_files & filenames
end

Class Method Details

.target_filesObject

Use RuboCop to produce a list of all files that should be scanned.



11
12
13
# File 'lib/ndr_dev_support/rubocop/executor.rb', line 11

def target_files
  @target_files ||= `rubocop -L`.each_line.map(&:strip)
end

Instance Method Details

#offenses_by_fileObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/ndr_dev_support/rubocop/executor.rb', line 20

def offenses_by_file
  return [] if @filenames.empty?

  escaped_paths = @filenames.map { |path| Shellwords.escape(path) }
  output = JSON.parse(`rubocop --format json #{escaped_paths.join(' ')}`)

  output['files'].each_with_object({}) do |file_output, result|
    result[file_output['path']] = file_output['offenses']
  end
end