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.



14
15
16
# File 'lib/pre-commit/checks/jslint_check.rb', line 14

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

Instance Attribute Details

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#check_nameObject



10
11
12
# File 'lib/pre-commit/checks/jslint_check.rb', line 10

def check_name
  "JSLint"
end

#files_to_checkObject



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

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

#linter_srcObject



36
37
38
# File 'lib/pre-commit/checks/jslint_check.rb', line 36

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

#run_check(file) ⇒ Object



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

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