Sha256: b6d930740348f288146874a96dac991170246a6f09a0780e0c76b710976e3ed7

Contents?: true

Size: 700 Bytes

Versions: 3

Compression:

Stored size: 700 Bytes

Contents

require 'pre-commit/checks/js_check'

module PreCommit
  class JshintCheck < JsCheck

    def check_name
      "JSHint"
    end

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

    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

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

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

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pre-commit-0.8.1 lib/pre-commit/checks/jshint_check.rb
pre-commit-0.8.0 lib/pre-commit/checks/jshint_check.rb
pre-commit-0.7.0 lib/pre-commit/checks/jshint_check.rb