Class: PreCommit::JshintCheck

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

Class Method Summary collapse

Methods inherited from JsCheck

call, display_error

Class Method Details

.check_nameObject



13
14
15
# File 'lib/pre-commit/checks/jshint_check.rb', line 13

def self.check_name
  "JSHint"
end

.configObject



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

def self.config
  if config_file = [ENV['JSHINT_CONFIG'], ".jshintrc"].compact.detect { |f| File.exist?(f) }
    ExecJS.exec("return (#{File.read(config_file)});")
  else
    {}
  end
end

.linter_srcObject



22
23
24
# File 'lib/pre-commit/checks/jshint_check.rb', line 22

def self.linter_src
  File.expand_path("../../support/jshint/jshint.js", __FILE__)
end

.run_check(file) ⇒ Object



17
18
19
20
# File 'lib/pre-commit/checks/jshint_check.rb', line 17

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