From 0baafd95ee9535f87bbbff34ac33c2ce211147b4 Mon Sep 17 00:00:00 2001
From: Zachary Carter <zack.carter@gmail.com>
Date: Mon, 18 Jun 2012 01:21:32 -0700
Subject: [PATCH] test for creation or references of global variables - issue
 #1731

---
 package.json            |  3 ++-
 tests/data/lib.jshintrc |  8 ++++++++
 tests/jshint-test.js    | 39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
 create mode 100644 tests/data/lib.jshintrc
 create mode 100755 tests/jshint-test.js

diff --git a/package.json b/package.json
index 7801ed885..eecc9a096 100644
--- a/package.json
+++ b/package.json
@@ -37,7 +37,8 @@
     "devDependencies": {
         "vows": "0.5.13",
         "awsbox": "0.2.12",
-        "irc": "0.3.3"
+        "irc": "0.3.3",
+        "jshint": "0.7.1"
     },
     "scripts": {
         "postinstall": "./scripts/generate_ephemeral_keys.sh",
diff --git a/tests/data/lib.jshintrc b/tests/data/lib.jshintrc
new file mode 100644
index 000000000..fa8c0257f
--- /dev/null
+++ b/tests/data/lib.jshintrc
@@ -0,0 +1,8 @@
+{
+  "undef": true,
+  "node": true,
+  "es5": true,
+  "esnext": true,
+  "strict": false,
+  "sub": true
+}
diff --git a/tests/jshint-test.js b/tests/jshint-test.js
new file mode 100755
index 000000000..21f057066
--- /dev/null
+++ b/tests/jshint-test.js
@@ -0,0 +1,39 @@
+#!/usr/bin/env node
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+require('./lib/test_env.js');
+
+// add lib/ to the require path
+
+const
+assert = require('assert'),
+vows = require('vows'),
+fs = require('fs'),
+path = require('path'),
+exec = require('child_process').exec;
+
+var suite = vows.describe('jshint');
+var jshintPath = '../node_modules/jshint/bin/hint';
+
+// disable vows (often flakey?) async error behavior
+suite.options.error = false;
+
+suite.addBatch({
+  "run jshint on the lib directory": {
+    topic: function () {
+      var child = exec(jshintPath + ' --config ./data/lib.jshintrc ../lib/ | grep "not defined"', {cwd: path.resolve(__dirname)}, this.callback);
+    },
+    "no globals are created or referenced" : function (error, stdout, stderr) {
+      var errors = stdout.split("\n").length - 1;
+      assert.strictEqual(errors, 0);
+    }
+  }
+});
+
+
+// run or export the suite.
+if (process.argv[1] === __filename) suite.run();
+else suite.export(module);
-- 
GitLab