Class: PDK::Validate::Rubocop

Inherits:
BaseValidator show all
Defined in:
lib/pdk/validators/ruby/rubocop.rb

Class Method Summary collapse

Methods inherited from BaseValidator

cmd_path, invoke, parse_targets

Class Method Details

.cmdObject



15
16
17
# File 'lib/pdk/validators/ruby/rubocop.rb', line 15

def self.cmd
  'rubocop'
end

.nameObject



11
12
13
# File 'lib/pdk/validators/ruby/rubocop.rb', line 11

def self.name
  'rubocop'
end

.parse_options(_options, targets) ⇒ Object



23
24
25
26
27
# File 'lib/pdk/validators/ruby/rubocop.rb', line 23

def self.parse_options(_options, targets)
  cmd_options = ['--format', 'json']

  cmd_options.concat(targets)
end

.parse_output(report, json_data) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pdk/validators/ruby/rubocop.rb', line 29

def self.parse_output(report, json_data)
  return unless json_data.key?('files')

  json_data['files'].each do |file_info|
    next unless file_info.key?('offenses')
    result = {
      file: file_info['path'],
      source: 'rubocop',
    }

    if file_info['offenses'].empty?
      report.add_event(result.merge(state: :passed, severity: :ok))
    else
      file_info['offenses'].each do |offense|
        report.add_event(
          result.merge(
            line:     offense['location']['line'],
            column:   offense['location']['column'],
            message:  offense['message'],
            severity: offense['severity'],
            test:     offense['cop_name'],
            state:    :failure,
          ),
        )
      end
    end
  end
end

.spinner_textObject



19
20
21
# File 'lib/pdk/validators/ruby/rubocop.rb', line 19

def self.spinner_text
  _('Checking Ruby code style')
end