From abe67b2850756730139775beb462ffe0b9910f26 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 17 Jun 2011 11:57:53 -0700 Subject: [PATCH] hacks for running as a git pre-commit hook. --- jslint | 2 +- run-jslint.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/jslint b/jslint index 3aad734..51a380a 100755 --- a/jslint +++ b/jslint @@ -3,4 +3,4 @@ # Follow symlinks to find the directory with the actual executable. [ "`readlink -f $0`" != "$0" ] && exec `readlink -f $0` "$@" -nodejs "`dirname $0`/run-jslint.js" "$@" +exec node "`dirname $0`/run-jslint.js" "$@" diff --git a/run-jslint.js b/run-jslint.js index 6134f20..2953c15 100755 --- a/run-jslint.js +++ b/run-jslint.js @@ -2,18 +2,29 @@ /*global require:false, process:false, sys:false */ (function (files) { + var sys = require('sys'); if (!files.length) { sys.puts("Usage: jslint file.js"); process.exit(1); } + files.forEach(function (file) { + if (file === "--ignore-no-files") { + return; + } var input, success, sys = require("sys"), fs = require("fs"), JSLINT = require('./fulljslint.js').JSLINT; - input = fs.readFileSync(file); + try { + input = fs.readFileSync(file); + } catch (e) { + sys.puts(e); + return; + } + if (!input) { sys.puts("jslint: Couldn't open file '" + file + "'."); return; @@ -43,6 +54,7 @@ sys.puts('\t' + (e.evidence || '').replace(/^\s+|\s+$/, "")); } }); + process.exit(2); } }); }(process.argv.slice(2)));