Class: PreCommit::JslintCheck

Inherits:
JsCheck
  • Object
show all
Defined in:
lib/pre-commit/checks/jslint_check.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from JsCheck

#call, #display_error, #reject_non_js, #run, #should_run?

Constructor Details

#initialize(type = :all) ⇒ JslintCheck

Returns a new instance of JslintCheck.



12
13
14
# File 'lib/pre-commit/checks/jslint_check.rb', line 12

def initialize(type = :all)
  @type = type
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/pre-commit/checks/jslint_check.rb', line 6

def type
  @type
end

Instance Method Details

#check_nameObject



8
9
10
# File 'lib/pre-commit/checks/jslint_check.rb', line 8

def check_name
  "JSLint"
end

#files_to_checkObject



16
17
18
19
20
21
22
23
# File 'lib/pre-commit/checks/jslint_check.rb', line 16

def files_to_check
  case @type
  when :new
    Utils.new_files('.').split(" ")
  else
    Utils.staged_files('.').split(" ")
  end
end

#linter_srcObject



34
35
36
# File 'lib/pre-commit/checks/jslint_check.rb', line 34

def linter_src
  File.join(PreCommit.root, 'lib', 'support', 'jslint', 'lint.js')
end

#run_check(file) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/pre-commit/checks/jslint_check.rb', line 25

def run_check(file)
  context = ExecJS.compile(File.read(linter_src))
  if !(context.call('JSLINT', File.read(file)))
    context.exec('return JSLINT.errors;')
  else
    []
  end
end