Class: LintTrap::Linter::Base

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

Overview

The base class for all linters. Provides a template for linter execution.

Constant Summary collapse

LintError =
Class.new(ExecutionError)
CONFIG_PATH =
File.expand_path('../../../../config', __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



15
16
17
# File 'lib/lint_trap/linter/base.rb', line 15

def initialize
  @languages = []
end

Instance Attribute Details

#languagesObject (readonly)

Returns the value of attribute languages.



13
14
15
# File 'lib/lint_trap/linter/base.rb', line 13

def languages
  @languages
end

#parserObject

Returns the value of attribute parser.



12
13
14
# File 'lib/lint_trap/linter/base.rb', line 12

def parser
  @parser
end

Instance Method Details

#==(other) ⇒ Object



59
60
61
62
63
# File 'lib/lint_trap/linter/base.rb', line 59

def ==(other)
  return false unless other.respond_to?(:name, true)

  name == other.name
end

#add_language(language) ⇒ Object



38
39
40
41
# File 'lib/lint_trap/linter/base.rb', line 38

def add_language(language)
  @languages << language
  language.add_linter(self)
end

#imageObject



51
52
53
# File 'lib/lint_trap/linter/base.rb', line 51

def image
  "lintci/#{name.downcase}"
end

#image_versionObject



55
56
57
# File 'lib/lint_trap/linter/base.rb', line 55

def image_version
  "#{image}:#{version}"
end

#inspectObject



65
66
67
# File 'lib/lint_trap/linter/base.rb', line 65

def inspect
  "<#{name}>"
end

#lint(files, container, options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lint_trap/linter/base.rb', line 19

def lint(files, container, options)
  violations_found, remaining_output = false, ''

  success = command(files, container, options).run(container) do |stdout|
    remaining_output = parser.parse(stdout, container) do |violation|
      violations_found = true
      yield violation
    end
  end

  if violations_found
    false
  elsif success
    true
  else
    raise LintError.new(command(files, container, options).to_s(container), remaining_output)
  end
end

#nameObject



43
44
45
# File 'lib/lint_trap/linter/base.rb', line 43

def name
  self.class.name.split('::').last
end

#versionObject

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/lint_trap/linter/base.rb', line 47

def version
  raise NotImplementedError, 'Must implement version.'
end