Class: LinterChanges::Linter::RuboCop::Adapter

Inherits:
Base
  • Object
show all
Defined in:
lib/linter/rubocop/adapter.rb

Constant Summary collapse

DEFAULT_CONFIG_FILES =

By default, anything containing rubocop on the file path will be consider a config file

[/rubocop/].freeze
DEFAULT_COMMAND =
'bin/rubocop'.freeze

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from LinterChanges::Linter::Base

Instance Method Details

#config_changed?(changed_files) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/linter/rubocop/adapter.rb', line 33

def config_changed?(changed_files)
  # Check if any of the config files have changed
  return true if super

  # TODO: get the location of Gemfile.lock with bundle command
  # Check if Gemfile.lock has changed and contains something related to rubocop
  if changed_files.include?('Gemfile.lock') && @git_diff.changed_lines_contains?(file: 'Gemfile.lock',
                                                                                pattern: 'rubocop')
    Logger.debug 'Something related to rubocop gem version changed in Gemfile.lock'
    return true
  end
  false
end

#list_target_filesObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/linter/rubocop/adapter.rb', line 11

def list_target_files
  cmd = "#{DEFAULT_COMMAND} --list-target-files"
  Logger.debug "Executing command: #{cmd}"

  stdout, stderr, status = Open3.capture3(cmd)
  unless status.success?
    Logger.error "Error listing RuboCop target files: #{stderr}"
    exit 1
  end

  stdout.strip.split("\n")
end

#run(files: []) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/linter/rubocop/adapter.rb', line 24

def run(files: [])
  cmd = if files.empty?
          @command
        else
          "#{@command} #{files.join(' ')}"
        end
  execute_linter(cmd)
end