Class: PreCommit::JshintCheck

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

Instance Method Summary collapse

Methods inherited from JsCheck

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

Instance Method Details

#check_nameObject



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

def check_name
  "JSHint"
end

#configObject



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

def config
  config_file = ENV['JSHINT_CONFIG']
  config_file ||= File.exists?(".jshintrc") ? ".jshintrc" : nil

  if config_file
    ExecJS.exec("return (#{File.read(config_file)});")
  else
    {}
  end
end

#files_to_checkObject



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

def files_to_check
  Utils.staged_files('.').split(" ")
end

#linter_srcObject



30
31
32
# File 'lib/pre-commit/checks/jshint_check.rb', line 30

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

#run_check(file) ⇒ Object



25
26
27
28
# File 'lib/pre-commit/checks/jshint_check.rb', line 25

def run_check(file)
  context = ExecJS.compile(File.read(linter_src))
  context.call('JSHINT', File.read(file), config)
end