lib/overcommit/plugins/pre_commit/js_syntax.rb in overcommit-0.1.4 vs lib/overcommit/plugins/pre_commit/js_syntax.rb in overcommit-0.1.5

- old
+ new

@@ -1,18 +1,28 @@ module Overcommit::GitHook class JSSyntax < HookSpecificCheck include HookRegistry file_type :js - JS_HINT_PATH = Overcommit::Utils.script_path 'jshint.js' - JS_HINT_RUNNER_PATH = Overcommit::Utils.script_path 'jshint_runner.js' - def run_check - return :warn, "Rhino is not installed" unless in_path? 'rhino' + return :warn, 'Need either `jshint` or `rhino` in path' unless runner - paths = staged.join(' ') + output = runner.call(staged.join(' ')).split("\n") + return (output.none? ? :good : :bad), output + end - output = `rhino -strict -f #{JS_HINT_PATH} #{JS_HINT_RUNNER_PATH} #{paths} 2>&1 | grep -v warning | grep -v -e '^js: '` - return (output !~ /^ERROR/ ? :good : :bad), output + private + + JS_HINT_PATH = Overcommit::Utils.script_path 'jshint.js' + JS_HINT_RUNNER_PATH = Overcommit::Utils.script_path 'jshint_runner.js' + + def runner + if in_path? 'jshint' + lambda { |paths| `jshint #{paths}` } + elsif in_path? 'rhino' + lambda do |paths| + `rhino -strict -f #{JS_HINT_PATH} #{JS_HINT_RUNNER_PATH} #{paths} 2>&1 | grep -v warning | grep -v -e '^js: '` + end + end end end end