Class: LinterChanges::Linter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/linter/base.rb

Direct Known Subclasses

RuboCop::Adapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_files: nil, command: nil, git_diff: nil) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
# File 'lib/linter/base.rb', line 8

def initialize(config_files: nil, command: nil, git_diff: nil)
  @name = self.class.name.split('::')[-2].downcase
  default_config_file = YAML.load_file("lib/linter/#{@name}/default_config.yml")
  @config_files = config_files || default_config_file['config_files']
  @command = command || default_config_file['command']
  @git_diff = git_diff
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/linter/base.rb', line 6

def name
  @name
end

Instance Method Details

#config_changed?(changed_files) ⇒ Boolean

Checks if any configuration files have changed

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/linter/base.rb', line 22

def config_changed?(changed_files)
  changed = @config_files.any? do |pattern|
    changed_files.any? { |file| file.match? Regexp.new(pattern) }
  end
  Logger.debug "#{@name.capitalize} configuration changed: #{changed}"
  changed
end

#list_target_filesObject

Returns an array of files that the linter targets

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/linter/base.rb', line 17

def list_target_files
  raise NotImplementedError, "#{self.class} must implement #list_target_files"
end

#run(files: []) ⇒ Object

Runs the linter on the specified files

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/linter/base.rb', line 31

def run(files: [])
  raise NotImplementedError, "#{self.class} must implement #run"
end