Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert all spaces to tabs.

This commit converts all spaces to tabs. This means that if you're
reading this message while using 'git blame' feel free to skip to
the previous commit to find the real author.

Sorry about that.
  • Loading branch information...
commit 0cc64419552b3422ed2d7a600e3047d442a10333 1 parent fc3dcbe
@valueof valueof authored
View
92 src/platforms/jsc.js
@@ -1,59 +1,59 @@
-/*jshint boss:true, evil:true, unused:true, undef:true */
/*global load, print, quit, JSHINT */
// usage:
-// jsc ${env_home}/jsc.js -- ${file} "$(cat ${file})" "option1:true,option2:false ${env_home}"
+// jsc ${env_home}/jsc.js -- ${file} "$(cat ${file})" "option1:true,option2:false ${env_home}"
var env_home = '';
if (arguments.length > 3) {
- env_home = arguments[3].toString().replace(/\/dist/, '/src/stable/');
+ env_home = arguments[3].toString().replace(/\/dist/, '/src/stable/');
}
load(env_home + "jshint.js");
if (typeof(JSHINT) === 'undefined') {
- print('jshint: Could not load jshint.js, tried "' + env_home + 'jshint.js".');
- quit();
+ print('jshint: Could not load jshint.js, tried "' + env_home + 'jshint.js".');
+ quit();
}
(function (args) {
- "use strict";
-
- var name = args[0],
- input = args[1],
- opts = (function (arg) {
- var opts = {};
- var item;
-
- switch (arg) {
- case undefined:
- case '':
- return opts;
- default:
- arg = arg.split(',');
- for (var i = 0, ii = arg.length; i < ii; i++) {
- item = arg[i].split(':');
- opts[item[0].replace(/(^\s*)|(\s*$)/g, '')] = eval(item[1]);
- }
- return opts;
- }
- })(args[2]);
-
- if (!name) {
- print('jshint: No file name was provided.');
- quit();
- }
-
- if (!input) {
- print('jshint: ' + name + ' contents were not provided to jshint.');
- quit();
- }
-
- if (!JSHINT(input, opts)) {
- for (var i = 0, err; err = JSHINT.errors[i]; i++) {
- print(err.reason + ' (line: ' + err.line + ', character: ' + err.character + ')');
- print('> ' + (err.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
- print('');
- }
- }
-
- quit();
+ "use strict";
+ /*jshint evil:true */
+
+ var name = args[0],
+ input = args[1],
+ opts = (function (arg) {
+ var opts = {};
+ var item;
+
+ switch (arg) {
+ case undefined:
+ case '':
+ return opts;
+ default:
+ arg = arg.split(',');
+ for (var i = 0, ii = arg.length; i < ii; i++) {
+ item = arg[i].split(':');
+ opts[item[0].replace(/(^\s*)|(\s*$)/g, '')] = eval(item[1]);
+ }
+ return opts;
+ }
+ })(args[2]);
+
+ if (!name) {
+ print('jshint: No file name was provided.');
+ quit();
+ }
+
+ if (!input) {
+ print('jshint: ' + name + ' contents were not provided to jshint.');
+ quit();
+ }
+
+ if (!JSHINT(input, opts)) {
+ for (var i = 0, err; err = JSHINT.errors[i]; i++) {
+ print(err.reason + ' (line: ' + err.line + ', character: ' + err.character + ')');
+ print('> ' + (err.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
+ print('');
+ }
+ }
+
+ quit();
})(arguments);
View
136 src/platforms/rhino.js
@@ -2,85 +2,85 @@
/*global JSHINT*/
(function (args) {
- "use strict";
+ "use strict";
- var filenames = [];
- var optstr; // arg1=val1,arg2=val2,...
- var predef; // global1=true,global2,global3,...
- var opts = {};
- var retval = 0;
+ var filenames = [];
+ var optstr; // arg1=val1,arg2=val2,...
+ var predef; // global1=true,global2,global3,...
+ var opts = {};
+ var retval = 0;
- args.forEach(function (arg) {
- if (arg.indexOf("=") > -1) {
- if (!optstr) {
- // First time it's the options.
- optstr = arg;
- } else {
- predef = arg;
- }
+ args.forEach(function (arg) {
+ if (arg.indexOf("=") > -1) {
+ if (!optstr) {
+ // First time it's the options.
+ optstr = arg;
+ } else {
+ predef = arg;
+ }
- return;
- }
+ return;
+ }
- if (optstr) {
- predef = arg;
- return;
- }
+ if (optstr) {
+ predef = arg;
+ return;
+ }
- filenames.push(arg);
- });
+ filenames.push(arg);
+ });
- if (filenames.length === 0) {
- print("Usage: jshint.js file.js");
- quit(1);
- }
+ if (filenames.length === 0) {
+ print("Usage: jshint.js file.js");
+ quit(1);
+ }
- if (optstr) {
- optstr.split(",").forEach(function (arg) {
- var o = arg.split("=");
- if (o[0] === "indent") {
- opts[o[0]] = parseInt(o[1], 10);
- } else {
- opts[o[0]] = (function (ov) {
- switch (ov) {
- case "true":
- return true;
- case "false":
- return false;
- default:
- return ov;
- }
- }(o[1]));
- }
- });
- }
+ if (optstr) {
+ optstr.split(",").forEach(function (arg) {
+ var o = arg.split("=");
+ if (o[0] === "indent") {
+ opts[o[0]] = parseInt(o[1], 10);
+ } else {
+ opts[o[0]] = (function (ov) {
+ switch (ov) {
+ case "true":
+ return true;
+ case "false":
+ return false;
+ default:
+ return ov;
+ }
+ }(o[1]));
+ }
+ });
+ }
- if (predef) {
- opts.predef = {};
+ if (predef) {
+ opts.predef = {};
- predef.split(",").forEach(function (arg) {
- var global = arg.split("=");
- opts.predef[global[0]] = global[1] === "true" ? true : false;
- });
- }
+ predef.split(",").forEach(function (arg) {
+ var global = arg.split("=");
+ opts.predef[global[0]] = global[1] === "true" ? true : false;
+ });
+ }
- filenames.forEach(function (name) {
- var input = readFile(name);
+ filenames.forEach(function (name) {
+ var input = readFile(name);
- if (!input) {
- print("jshint: Couldn't open file " + name);
- quit(1);
- }
+ if (!input) {
+ print("jshint: Couldn't open file " + name);
+ quit(1);
+ }
- if (!JSHINT(input, opts)) {
- for (var i = 0, err; err = JSHINT.errors[i]; i += 1) {
- print(err.reason + " (" + name + ":" + err.line + ":" + err.character + ")");
- print("> " + (err.evidence || "").replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
- print("");
- }
- retval = 1;
- }
- });
+ if (!JSHINT(input, opts)) {
+ for (var i = 0, err; err = JSHINT.errors[i]; i += 1) {
+ print(err.reason + " (" + name + ":" + err.line + ":" + err.character + ")");
+ print("> " + (err.evidence || "").replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
+ print("");
+ }
+ retval = 1;
+ }
+ });
- quit(retval);
+ quit(retval);
}(arguments));
View
182 src/reporters/checkstyle.js
@@ -2,106 +2,106 @@
// http://github.com/relaxnow
module.exports =
{
- reporter: function (results, data)
- {
- "use strict";
+ reporter: function (results, data)
+ {
+ "use strict";
- var files = {},
- out = [],
- pairs = {
- "&": "&amp;",
- '"': "&quot;",
- "'": "&apos;",
- "<": "&lt;",
- ">": "&gt;"
- },
- file, fileName, i, issue, globals, unuseds;
+ var files = {},
+ out = [],
+ pairs = {
+ "&": "&amp;",
+ '"': "&quot;",
+ "'": "&apos;",
+ "<": "&lt;",
+ ">": "&gt;"
+ },
+ file, fileName, i, issue, globals, unuseds;
- function encode(s) {
- for (var r in pairs) {
- if (typeof(s) !== "undefined") {
- s = s.replace(new RegExp(r, "g"), pairs[r]);
- }
- }
- return s || "";
- }
+ function encode(s) {
+ for (var r in pairs) {
+ if (typeof(s) !== "undefined") {
+ s = s.replace(new RegExp(r, "g"), pairs[r]);
+ }
+ }
+ return s || "";
+ }
- results.forEach(function (result) {
- // Register the file
- result.file = result.file.replace(/^\.\//, '');
- if (!files[result.file]) {
- files[result.file] = [];
- }
+ results.forEach(function (result) {
+ // Register the file
+ result.file = result.file.replace(/^\.\//, '');
+ if (!files[result.file]) {
+ files[result.file] = [];
+ }
- // Add the error
- files[result.file].push({
- severity: 'error',
- line: result.error.line,
- column: result.error.character,
- message: result.error.reason,
- source: result.error.raw
- });
- });
+ // Add the error
+ files[result.file].push({
+ severity: 'error',
+ line: result.error.line,
+ column: result.error.character,
+ message: result.error.reason,
+ source: result.error.raw
+ });
+ });
- data.forEach(function (result) {
- file = data.file;
- globals = result.implieds;
- unuseds = result.unused;
+ data.forEach(function (result) {
+ file = data.file;
+ globals = result.implieds;
+ unuseds = result.unused;
- // Register the file
- result.file = result.file.replace(/^\.\//, '');
- if (!files[result.file]) {
- files[result.file] = [];
- }
+ // Register the file
+ result.file = result.file.replace(/^\.\//, '');
+ if (!files[result.file]) {
+ files[result.file] = [];
+ }
- if (globals) {
- globals.forEach(function (global) {
- files[result.file].push({
- severity: 'warning',
- line: global.line,
- column: 0,
- message: "Implied global '" + global.name + "'",
- source: 'jshint.implied-globals'
- });
- });
- }
- if (unuseds) {
- unuseds.forEach(function (unused) {
- files[result.file].push({
- severity: 'warning',
- line: unused.line,
- column: 0,
- message: "Unused variable: '" + unused.name + "'",
- source: 'jshint.implied-unuseds'
- });
- });
- }
- });
+ if (globals) {
+ globals.forEach(function (global) {
+ files[result.file].push({
+ severity: 'warning',
+ line: global.line,
+ column: 0,
+ message: "Implied global '" + global.name + "'",
+ source: 'jshint.implied-globals'
+ });
+ });
+ }
+ if (unuseds) {
+ unuseds.forEach(function (unused) {
+ files[result.file].push({
+ severity: 'warning',
+ line: unused.line,
+ column: 0,
+ message: "Unused variable: '" + unused.name + "'",
+ source: 'jshint.implied-unuseds'
+ });
+ });
+ }
+ });
- out.push("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
- out.push("<checkstyle version=\"4.3\">");
+ out.push("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
+ out.push("<checkstyle version=\"4.3\">");
- for (fileName in files) {
- if (files.hasOwnProperty(fileName)) {
- out.push("\t<file name=\"" + fileName + "\">");
- for (i = 0; i < files[fileName].length; i++) {
- issue = files[fileName][i];
- out.push(
- "\t\t<error " +
- "line=\"" + issue.line + "\" " +
- "column=\"" + issue.column + "\" " +
- "severity=\"" + issue.severity + "\" " +
- "message=\"" + encode(issue.message) + "\" " +
- "source=\"" + encode(issue.source) + "\" " +
- "/>"
- );
- }
- out.push("\t</file>");
- }
- }
+ for (fileName in files) {
+ if (files.hasOwnProperty(fileName)) {
+ out.push("\t<file name=\"" + fileName + "\">");
+ for (i = 0; i < files[fileName].length; i++) {
+ issue = files[fileName][i];
+ out.push(
+ "\t\t<error " +
+ "line=\"" + issue.line + "\" " +
+ "column=\"" + issue.column + "\" " +
+ "severity=\"" + issue.severity + "\" " +
+ "message=\"" + encode(issue.message) + "\" " +
+ "source=\"" + encode(issue.source) + "\" " +
+ "/>"
+ );
+ }
+ out.push("\t</file>");
+ }
+ }
- out.push("</checkstyle>");
+ out.push("</checkstyle>");
- process.stdout.write(out.join("\n") + "\n");
- }
+ process.stdout.write(out.join("\n") + "\n");
+ }
};
View
27 src/reporters/default.js
@@ -1,20 +1,19 @@
"use strict";
module.exports = {
- reporter: function (results) {
- var len = results.length,
- str = '',
- file, error;
+ reporter: function (results) {
+ var len = results.length;
+ var str = '';
- results.forEach(function (result) {
- file = result.file;
- error = result.error;
- str += file + ': line ' + error.line + ', col ' +
- error.character + ', ' + error.reason + '\n';
- });
+ results.forEach(function (result) {
+ var file = result.file;
+ var error = result.error;
+ str += file + ': line ' + error.line + ', col ' +
+ error.character + ', ' + error.reason + '\n';
+ });
- if (str) {
- process.stdout.write(str + "\n" + len + ' error' + ((len === 1) ? '' : 's') + "\n");
- }
- }
+ if (str) {
+ process.stdout.write(str + "\n" + len + ' error' + ((len === 1) ? '' : 's') + "\n");
+ }
+ }
};
View
102 src/reporters/jslint_xml.js
@@ -2,55 +2,55 @@
// http://github.com/vsviridov
module.exports =
{
- reporter: function (results)
- {
- "use strict";
-
- var files = {},
- out = [],
- pairs = {
- "&": "&amp;",
- '"': "&quot;",
- "'": "&apos;",
- "<": "&lt;",
- ">": "&gt;"
- },
- file, i, issue;
-
- function encode(s) {
- for (var r in pairs) {
- if (typeof(s) !== "undefined") {
- s = s.replace(new RegExp(r, "g"), pairs[r]);
- }
- }
- return s || "";
- }
-
-
- results.forEach(function (result) {
- result.file = result.file.replace(/^\.\//, '');
- if (!files[result.file]) {
- files[result.file] = [];
- }
- files[result.file].push(result.error);
- });
-
- out.push("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
- out.push("<jslint>");
-
- for (file in files) {
- out.push("\t<file name=\"" + file + "\">");
- for (i = 0; i < files[file].length; i++) {
- issue = files[file][i];
- out.push("\t\t<issue line=\"" + issue.line + "\" char=\"" +
- issue.character + "\" reason=\"" + encode(issue.reason) +
- "\" evidence=\"" + encode(issue.evidence) + "\" />");
- }
- out.push("\t</file>");
- }
-
- out.push("</jslint>");
-
- process.stdout.write(out.join("\n") + "\n");
- }
+ reporter: function (results)
+ {
+ "use strict";
+
+ var files = {},
+ out = [],
+ pairs = {
+ "&": "&amp;",
+ '"': "&quot;",
+ "'": "&apos;",
+ "<": "&lt;",
+ ">": "&gt;"
+ },
+ file, i, issue;
+
+ function encode(s) {
+ for (var r in pairs) {
+ if (typeof(s) !== "undefined") {
+ s = s.replace(new RegExp(r, "g"), pairs[r]);
+ }
+ }
+ return s || "";
+ }
+
+
+ results.forEach(function (result) {
+ result.file = result.file.replace(/^\.\//, '');
+ if (!files[result.file]) {
+ files[result.file] = [];
+ }
+ files[result.file].push(result.error);
+ });
+
+ out.push("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
+ out.push("<jslint>");
+
+ for (file in files) {
+ out.push("\t<file name=\"" + file + "\">");
+ for (i = 0; i < files[file].length; i++) {
+ issue = files[file][i];
+ out.push("\t\t<issue line=\"" + issue.line + "\" char=\"" +
+ issue.character + "\" reason=\"" + encode(issue.reason) +
+ "\" evidence=\"" + encode(issue.evidence) + "\" />");
+ }
+ out.push("\t</file>");
+ }
+
+ out.push("</jslint>");
+
+ process.stdout.write(out.join("\n") + "\n");
+ }
};
View
70 src/reporters/non_error.js
@@ -1,45 +1,45 @@
"use strict";
module.exports = {
- reporter: function (results, data) {
- var len = results.length,
- str = '',
- file, error, globals, unuseds;
+ reporter: function (results, data) {
+ var len = results.length,
+ str = '',
+ file, error, globals, unuseds;
- results.forEach(function (result) {
- file = result.file;
- error = result.error;
- str += file + ': line ' + error.line + ', col ' +
- error.character + ', ' + error.reason + '\n';
- });
+ results.forEach(function (result) {
+ file = result.file;
+ error = result.error;
+ str += file + ': line ' + error.line + ', col ' +
+ error.character + ', ' + error.reason + '\n';
+ });
- str += len > 0 ? ("\n" + len + ' error' + ((len === 1) ? '' : 's')) : "";
+ str += len > 0 ? ("\n" + len + ' error' + ((len === 1) ? '' : 's')) : "";
- data.forEach(function (data) {
- file = data.file;
- globals = data.implieds;
- unuseds = data.unused;
+ data.forEach(function (data) {
+ file = data.file;
+ globals = data.implieds;
+ unuseds = data.unused;
- if (globals || unuseds) {
- str += '\n\n' + file + ' :\n';
- }
+ if (globals || unuseds) {
+ str += '\n\n' + file + ' :\n';
+ }
- if (globals) {
- str += '\tImplied globals:\n';
- globals.forEach(function (global) {
- str += '\t\t' + global.name + ': ' + global.line + '\n';
- });
- }
- if (unuseds) {
- str += '\tUnused Variables:\n\t\t';
- unuseds.forEach(function (unused) {
- str += unused.name + '(' + unused.line + '), ';
- });
- }
- });
+ if (globals) {
+ str += '\tImplied globals:\n';
+ globals.forEach(function (global) {
+ str += '\t\t' + global.name + ': ' + global.line + '\n';
+ });
+ }
+ if (unuseds) {
+ str += '\tUnused Variables:\n\t\t';
+ unuseds.forEach(function (unused) {
+ str += unused.name + '(' + unused.line + '), ';
+ });
+ }
+ });
- if (str) {
- process.stdout.write(str + "\n");
- }
- }
+ if (str) {
+ process.stdout.write(str + "\n");
+ }
+ }
};
View
9,225 src/stable/jshint.js
4,615 additions, 4,610 deletions not shown
View
156 tests/stable/helpers/coveraje.js
@@ -1,82 +1,82 @@
/*jshint node: true*/
(function () {
- "use strict";
-
- var coveraje = require("coveraje").coveraje,
- fs = require("fs"),
- path = require("path");
- var filePath = path.resolve(path.join(__dirname, "../../jshint.js"));
-
- function runTests(file, helper) {
- return function (context) {
- // hack: set cache value
- require.cache[filePath] = {
- id: filePath,
- exports: context.exports,
- loaded: true
- };
-
- return coveraje.runHelper(helper).run(file);
- };
- }
-
- var tests = {};
- var rd = path.join(__dirname, "..");
-
- function collect(dirs) {
- var l = dirs.length;
- var r = 0;
-
- function onDir(dirPath) {
- return function (err, files) {
- r += 1;
-
- if (!err) {
- files.forEach(function (f) {
- var p = path.join(dirPath, f);
- var stat;
-
- try {
- stat = fs.statSync(p);
- } catch (ex) {
- return;
- }
-
- if (stat.isFile()) {
- tests[path.relative(rd, p)] = runTests(path.join(dirPath, f), "expresso");
- }
- });
- }
-
- if (r === l) { // all dirs loaded
- coveraje.cover(
- function () {
- // always read the content from disk, so changes can be refreshed in the browser
- try {
- return fs.readFileSync(filePath, 'utf-8');
- } catch (ex) {
- return "{ /*" + ex.message + "*/ }";
- }
- },
- tests,
- {
- useServer: true,
- globals: "node"
- }
- );
- }
-
- };
- }
-
-
- for (var i = 0; i < l; i += 1) {
- var subPath = path.join(rd, dirs[i]);
-
- fs.readdir(subPath, onDir(subPath));
- }
- }
-
- collect(["unit", "regression"]);
+ "use strict";
+
+ var coveraje = require("coveraje").coveraje,
+ fs = require("fs"),
+ path = require("path");
+ var filePath = path.resolve(path.join(__dirname, "../../jshint.js"));
+
+ function runTests(file, helper) {
+ return function (context) {
+ // hack: set cache value
+ require.cache[filePath] = {
+ id: filePath,
+ exports: context.exports,
+ loaded: true
+ };
+
+ return coveraje.runHelper(helper).run(file);
+ };
+ }
+
+ var tests = {};
+ var rd = path.join(__dirname, "..");
+
+ function collect(dirs) {
+ var l = dirs.length;
+ var r = 0;
+
+ function onDir(dirPath) {
+ return function (err, files) {
+ r += 1;
+
+ if (!err) {
+ files.forEach(function (f) {
+ var p = path.join(dirPath, f);
+ var stat;
+
+ try {
+ stat = fs.statSync(p);
+ } catch (ex) {
+ return;
+ }
+
+ if (stat.isFile()) {
+ tests[path.relative(rd, p)] = runTests(path.join(dirPath, f), "expresso");
+ }
+ });
+ }
+
+ if (r === l) { // all dirs loaded
+ coveraje.cover(
+ function () {
+ // always read the content from disk, so changes can be refreshed in the browser
+ try {
+ return fs.readFileSync(filePath, 'utf-8');
+ } catch (ex) {
+ return "{ /*" + ex.message + "*/ }";
+ }
+ },
+ tests,
+ {
+ useServer: true,
+ globals: "node"
+ }
+ );
+ }
+
+ };
+ }
+
+
+ for (var i = 0; i < l; i += 1) {
+ var subPath = path.join(rd, dirs[i]);
+
+ fs.readdir(subPath, onDir(subPath));
+ }
+ }
+
+ collect(["unit", "regression"]);
}());
View
4 tests/stable/helpers/fixture.js
@@ -3,5 +3,5 @@
var fs = require('fs');
exports.fixture = function (name) {
- return fs.readFileSync(__dirname + '/../unit/fixtures/' + name).toString();
-};
+ return fs.readFileSync(__dirname + '/../unit/fixtures/' + name).toString();
+};
View
246 tests/stable/helpers/testhelper.js
@@ -5,25 +5,25 @@
*
* Use it with method chaining, so you get something like
*
- * var TestRun = require("./testhelper").setup.testRun;
+ * var TestRun = require("./testhelper").setup.testRun;
*
- * TestRun(test, name)
- * .addError(line, errorMessage)
- * .test(source, options);
+ * TestRun(test, name)
+ * .addError(line, errorMessage)
+ * .test(source, options);
*
* TestRun(test, name)
- * test: nodeunit test object
- * name: optional. name of the test run
- * with a name, it's easier to identify a test run
+ * test: nodeunit test object
+ * name: optional. name of the test run
+ * with a name, it's easier to identify a test run
*
* .addError(line, errorMessage)
- * line: line of the error message
- * errorMessage: the message of the reported error
+ * line: line of the error message
+ * errorMessage: the message of the reported error
*
* .test(source, options)
- * starts the test run
- * source: source of the test file
- * options: optional. the options for jshint
+ * starts the test run
+ * source: source of the test file
+ * options: optional. the options for jshint
*/
/*jshint node: true, eqnull: true*/
@@ -31,118 +31,118 @@
var JSHINT = require('../../../src/stable/jshint.js').JSHINT;
if (exports.setup === undefined || exports.setup === null) {
- exports.setup = {};
+ exports.setup = {};
}
exports.setup.testRun = function (test, name) {
- var initCounter = 0, runCounter = 0, seq = 0, checked = [], definedErrors = [];
-
- var helperObj = {
- addError: function (line, message, extras) {
- definedErrors.push({
- line: line,
- message: message,
- extras: extras
- });
-
- return helperObj;
- },
-
- test: function (source, options, globals) {
- var ret = !!JSHINT(source, options, globals);
- var errors = JSHINT.errors.filter(function (er) {
- return er && er.id === "(error)";
- });
-
- if (errors.length === 0 && definedErrors.length === 0) {
- return;
- }
-
- // filter all thrown errors
- var undefinedErrors = errors.filter(function (er) {
- return !definedErrors.some(function (def) {
- var result = def.line === er.line &&
- def.message === er.reason;
-
- if (!result) {
- return result;
- }
-
- if (def.extras) {
- for (var extra in def.extras) {
- if (def.extras.hasOwnProperty(extra) &&
- er.hasOwnProperty(extra)) {
- result = (def.extras[extra] === er[extra]);
- if (!result) {
- return result;
- }
- }
- }
- }
- return result;
- });
- });
-
- // filter all defined errors
- var unthrownErrors = definedErrors.filter(function (def) {
- return !errors.some(function (er) {
- return def.line === er.line &&
- def.message === er.reason;
- });
- });
-
- // elements that only differs in line number
- var wrongLineNumbers = undefinedErrors.map(function (er) {
- var lines = unthrownErrors.filter(function (def) {
- return def.line !== er.line &&
- def.message === er.reason;
- }).map(function (def) {
- return def.line;
- });
-
- if (lines.length) {
- return {
- line: er.line,
- message: er.reason,
- definedIn: lines
- };
- }
- return null;
- }).filter(function (er) {
- return !!er;
- });
-
- // remove undefined errors, if there is a definition with wrong line number
- undefinedErrors = undefinedErrors.filter(function (er) {
- return !wrongLineNumbers.some(function (def) {
- return def.message === er.reason;
- });
- });
- unthrownErrors = unthrownErrors.filter(function (er) {
- return !wrongLineNumbers.some(function (def) {
- return def.message === er.message;
- });
- });
-
- test.ok(
- undefinedErrors.length === 0 && unthrownErrors.length === 0 && wrongLineNumbers.length === 0,
-
- (name == null ? "" : "\n TestRun: [bold]{" + name + "}") +
- unthrownErrors.map(function (el, idx) {
- return (idx === 0 ? "\n [yellow]{Errors defined, but not thrown by JSHINT}\n" : "") +
- " [bold]{Line " + el.line + ", Char " + el.character + "} " + el.message;
- }).join("\n") +
- undefinedErrors.map(function (el, idx) {
- return (idx === 0 ? "\n [yellow]{Errors thrown by JSHINT, but not defined in test run}\n" : "") +
- " [bold]{Line " + el.line + ", Char " + el.character + "} " + el.reason;
- }).join("\n") +
- wrongLineNumbers.map(function (el, idx) {
- return (idx === 0 ? "\n [yellow]{Errors with wrong line number}\n" : "") +
- " [bold]{Line " + el.line + "} " + el.message + " [red]{not in line(s)} [bold]{" + el.definedIn.join(", ") + "}";
- }).join("\n") + "\n"
- );
- }
- };
-
- return helperObj;
+ var initCounter = 0, runCounter = 0, seq = 0, checked = [], definedErrors = [];
+
+ var helperObj = {
+ addError: function (line, message, extras) {
+ definedErrors.push({
+ line: line,
+ message: message,
+ extras: extras
+ });
+
+ return helperObj;
+ },
+
+ test: function (source, options, globals) {
+ var ret = !!JSHINT(source, options, globals);
+ var errors = JSHINT.errors.filter(function (er) {
+ return er && er.id === "(error)";
+ });
+
+ if (errors.length === 0 && definedErrors.length === 0) {
+ return;
+ }
+
+ // filter all thrown errors
+ var undefinedErrors = errors.filter(function (er) {
+ return !definedErrors.some(function (def) {
+ var result = def.line === er.line &&
+ def.message === er.reason;
+
+ if (!result) {
+ return result;
+ }
+
+ if (def.extras) {
+ for (var extra in def.extras) {
+ if (def.extras.hasOwnProperty(extra) &&
+ er.hasOwnProperty(extra)) {
+ result = (def.extras[extra] === er[extra]);
+ if (!result) {
+ return result;
+ }
+ }
+ }
+ }
+ return result;
+ });
+ });
+
+ // filter all defined errors
+ var unthrownErrors = definedErrors.filter(function (def) {
+ return !errors.some(function (er) {
+ return def.line === er.line &&
+ def.message === er.reason;
+ });
+ });
+
+ // elements that only differs in line number
+ var wrongLineNumbers = undefinedErrors.map(function (er) {
+ var lines = unthrownErrors.filter(function (def) {
+ return def.line !== er.line &&
+ def.message === er.reason;
+ }).map(function (def) {
+ return def.line;
+ });
+
+ if (lines.length) {
+ return {
+ line: er.line,
+ message: er.reason,
+ definedIn: lines
+ };
+ }
+ return null;
+ }).filter(function (er) {
+ return !!er;
+ });
+
+ // remove undefined errors, if there is a definition with wrong line number
+ undefinedErrors = undefinedErrors.filter(function (er) {
+ return !wrongLineNumbers.some(function (def) {
+ return def.message === er.reason;
+ });
+ });
+ unthrownErrors = unthrownErrors.filter(function (er) {
+ return !wrongLineNumbers.some(function (def) {
+ return def.message === er.message;
+ });
+ });
+
+ test.ok(
+ undefinedErrors.length === 0 && unthrownErrors.length === 0 && wrongLineNumbers.length === 0,
+
+ (name == null ? "" : "\n TestRun: [bold]{" + name + "}") +
+ unthrownErrors.map(function (el, idx) {
+ return (idx === 0 ? "\n [yellow]{Errors defined, but not thrown by JSHINT}\n" : "") +
+ " [bold]{Line " + el.line + ", Char " + el.character + "} " + el.message;
+ }).join("\n") +
+ undefinedErrors.map(function (el, idx) {
+ return (idx === 0 ? "\n [yellow]{Errors thrown by JSHINT, but not defined in test run}\n" : "") +
+ " [bold]{Line " + el.line + ", Char " + el.character + "} " + el.reason;
+ }).join("\n") +
+ wrongLineNumbers.map(function (el, idx) {
+ return (idx === 0 ? "\n [yellow]{Errors with wrong line number}\n" : "") +
+ " [bold]{Line " + el.line + "} " + el.message + " [red]{not in line(s)} [bold]{" + el.definedIn.join(", ") + "}";
+ }).join("\n") + "\n"
+ );
+ }
+ };
+
+ return helperObj;
};
View
580 tests/stable/unit/core.js
@@ -1,7 +1,7 @@
"use strict";
-var JSHINT = require('../../../src/stable/jshint.js').JSHINT;
-var fs = require('fs');
+var JSHINT = require('../../../src/stable/jshint.js').JSHINT;
+var fs = require('fs');
var TestRun = require("../helpers/testhelper").setup.testRun;
/**
@@ -9,112 +9,112 @@ var TestRun = require("../helpers/testhelper").setup.testRun;
* function so it is not necessary to spam code with jshint-related comments
*/
exports.testCustomGlobals = function (test) {
- var code = '(function (test) { return [ fooGlobal, barGlobal ]; }());';
- var custom = { fooGlobal: false, barGlobal: false };
+ var code = '(function (test) { return [ fooGlobal, barGlobal ]; }());';
+ var custom = { fooGlobal: false, barGlobal: false };
- test.ok(JSHINT(code, {}, custom));
+ test.ok(JSHINT(code, {}, custom));
- var report = JSHINT.data();
- test.strictEqual(report.implieds, undefined);
- test.equal(report.globals.length, 2);
+ var report = JSHINT.data();
+ test.strictEqual(report.implieds, undefined);
+ test.equal(report.globals.length, 2);
- var dict = {};
- for (var i = 0, g; g = report.globals[i]; i += 1)
- dict[g] = true;
+ var dict = {};
+ for (var i = 0, g; g = report.globals[i]; i += 1)
+ dict[g] = true;
- for (i = 0, g = null; g = custom[i]; i += 1)
- test.ok(g in dict);
+ for (i = 0, g = null; g = custom[i]; i += 1)
+ test.ok(g in dict);
- test.done();
+ test.done();
};
exports.testUnusedDefinedGlobals = function (test) {
- var src = fs.readFileSync(__dirname + "/fixtures/unusedglobals.js", "utf8");
+ var src = fs.readFileSync(__dirname + "/fixtures/unusedglobals.js", "utf8");
- TestRun(test)
- .addError(2, "'bar' is defined but never used.")
- .test(src, { unused: true });
+ TestRun(test)
+ .addError(2, "'bar' is defined but never used.")
+ .test(src, { unused: true });
- test.done();
+ test.done();
};
/** Test that JSHint recognizes `new Array(<expr>)` as a valid expression */
exports.testNewArray = function (test) {
- var code = 'new Array(1);';
- var code1 = 'new Array(v + 1);';
- var code2 = 'new Array("hello", "there", "chaps");';
+ var code = 'new Array(1);';
+ var code1 = 'new Array(v + 1);';
+ var code2 = 'new Array("hello", "there", "chaps");';
- TestRun(test).test(code);
- TestRun(test).test(code1);
- TestRun(test).test(code2);
+ TestRun(test).test(code);
+ TestRun(test).test(code1);
+ TestRun(test).test(code2);
- TestRun(test)
- .addError(1, "Use the array literal notation [].")
- .test('new Array();');
+ TestRun(test)
+ .addError(1, "Use the array literal notation [].")
+ .test('new Array();');
- test.done();
+ test.done();
};
/** Test that JSHint recognizes `new foo.Array(<expr>)` as a valid expression #527 **/
exports.testNewNonNativeArray = function (test) {
- var code = 'new foo.Array();';
- var code1 = 'new foo.Array(1);';
- var code2 = 'new foo.Array(v + 1);';
- var code3 = 'new foo.Array("hello", "there", "chaps");';
+ var code = 'new foo.Array();';
+ var code1 = 'new foo.Array(1);';
+ var code2 = 'new foo.Array(v + 1);';
+ var code3 = 'new foo.Array("hello", "there", "chaps");';
- TestRun(test).test(code);
- TestRun(test).test(code1);
- TestRun(test).test(code2);
- TestRun(test).test(code3);
+ TestRun(test).test(code);
+ TestRun(test).test(code1);
+ TestRun(test).test(code2);
+ TestRun(test).test(code3);
- test.done();
+ test.done();
};
exports.testNonNativeArray = function (test) {
- var code1 = 'foo.Array();';
- var code2 = 'foo.Array(v + 1);';
- var code3 = 'foo.Array("hello", "there", "chaps");';
+ var code1 = 'foo.Array();';
+ var code2 = 'foo.Array(v + 1);';
+ var code3 = 'foo.Array("hello", "there", "chaps");';
- TestRun(test).test(code1);
- TestRun(test).test(code2);
- TestRun(test).test(code3);
+ TestRun(test).test(code1);
+ TestRun(test).test(code2);
+ TestRun(test).test(code3);
- test.done();
+ test.done();
};
/** Test that JSHint recognizes `new Object(<expr>)` as a valid expression */
exports.testNewObject = function (test) {
- var code = 'Object(1);';
- var code1 = 'new Object(1);';
+ var code = 'Object(1);';
+ var code1 = 'new Object(1);';
- TestRun(test).test(code);
- TestRun(test).test(code1);
+ TestRun(test).test(code);
+ TestRun(test).test(code1);
- TestRun(test)
- .addError(1, "Use the object literal notation {}.")
- .test('Object();');
+ TestRun(test)
+ .addError(1, "Use the object literal notation {}.")
+ .test('Object();');
- TestRun(test)
- .addError(1, "Use the object literal notation {}.")
- .test('new Object();');
+ TestRun(test)
+ .addError(1, "Use the object literal notation {}.")
+ .test('new Object();');
- test.done();
+ test.done();
};
/** Test that JSHint recognizes `new foo.Object(<expr>)` as a valid expression #527 **/
exports.testNewNonNativeObject = function (test) {
- var code = 'new foo.Object();';
- var code1 = 'new foo.Object(1);';
- var code2 = 'foo.Object();';
- var code3 = 'foo.Object(1);';
+ var code = 'new foo.Object();';
+ var code1 = 'new foo.Object(1);';
+ var code2 = 'foo.Object();';
+ var code3 = 'foo.Object(1);';
- TestRun(test).test(code);
- TestRun(test).test(code1);
- TestRun(test).test(code2);
- TestRun(test).test(code3);
+ TestRun(test).test(code);
+ TestRun(test).test(code1);
+ TestRun(test).test(code2);
+ TestRun(test).test(code3);
- test.done();
+ test.done();
};
@@ -126,23 +126,23 @@ exports.testNewNonNativeObject = function (test) {
* More info: https://gist.github.com/315916
*/
exports.testUndefinedAsParam = function (test) {
- var code = '(function (undefined) {}());';
- var code1 = 'var undefined = 1;';
+ var code = '(function (undefined) {}());';
+ var code1 = 'var undefined = 1;';
- TestRun(test).test(code);
+ TestRun(test).test(code);
- // But it must never tolerate reassigning of undefined
- TestRun(test)
- .addError(1, "Expected an identifier and instead saw 'undefined' (a reserved word).")
- .test(code1);
+ // But it must never tolerate reassigning of undefined
+ TestRun(test)
+ .addError(1, "Expected an identifier and instead saw 'undefined' (a reserved word).")
+ .test(code1);
- test.done();
+ test.done();
};
/** Tests that JSHint accepts new line after a dot (.) operator */
exports.newLineAfterDot = function (test) {
- TestRun(test).test([ "chain().chain().", "chain();" ]);
- test.done();
+ TestRun(test).test([ "chain().chain().", "chain();" ]);
+ test.done();
};
/**
@@ -150,11 +150,11 @@ exports.newLineAfterDot = function (test) {
* More info: http://perfectionkills.com/understanding-delete/
*/
exports.noDelete = function (test) {
- TestRun(test)
- .addError(1, 'Variables should not be deleted.')
- .test('delete NullReference;');
+ TestRun(test)
+ .addError(1, 'Variables should not be deleted.')
+ .test('delete NullReference;');
- test.done();
+ test.done();
};
/**
@@ -162,352 +162,352 @@ exports.noDelete = function (test) {
* using special comments.
*/
exports.switchFallThrough = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/switchFallThrough.js', 'utf8');
- TestRun(test)
- .addError(3, "Expected a 'break' statement before 'case'.")
- .addError(18, "Expected a 'break' statement before 'default'.")
- .addError(36, "Unexpected ':'.")
- .test(src);
+ var src = fs.readFileSync(__dirname + '/fixtures/switchFallThrough.js', 'utf8');
+ TestRun(test)
+ .addError(3, "Expected a 'break' statement before 'case'.")
+ .addError(18, "Expected a 'break' statement before 'default'.")
+ .addError(36, "Unexpected ':'.")
+ .test(src);
- test.done();
+ test.done();
};
exports.testVoid = function (test) {
- var code = [
- "void(0);",
- "void 0;",
- "var a = void(1);"
- ];
- TestRun(test).test(code);
+ var code = [
+ "void(0);",
+ "void 0;",
+ "var a = void(1);"
+ ];
+ TestRun(test).test(code);
- test.done();
+ test.done();
};
exports.testMissingSpaces = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/missingspaces.js', 'utf8');
- TestRun(test)
- .addError(1, "Missing space after 'function'.", { character: 17 })
- .addError(2, "Missing space after 'b'.", { character: 6 })
- .addError(2, "Missing space after '='.", { character: 7 })
- .addError(2, "Missing space after ')'.", { character: 18 })
- .addError(3, "Missing space after 'd'.", { character: 6 })
- .addError(4, "Missing space after ')'.", { character: 13 })
- .addError(5, "Missing space after '1'.", { character: 13 })
- .addError(7, "Missing space after '2'.", { character: 10 })
- .addError(7, "Missing space after '+'.", { character: 11 })
- .addError(8, "Missing space after '/'.", { character: 14 })
- .addError(8, "Missing space after '+'.", { character: 15 })
- .addError(8, "Missing space after 'uid'.", { character: 20 })
- .addError(8, "Missing space after '+'.", { character: 21 })
- .addError(8, "Missing space after '/likes?access_token='.", { character: 43 })
- .addError(8, "Missing space after '+'.", { character: 44 })
- .test(src, { white: true });
-
- test.done();
+ var src = fs.readFileSync(__dirname + '/fixtures/missingspaces.js', 'utf8');
+ TestRun(test)
+ .addError(1, "Missing space after 'function'.", { character: 17 })
+ .addError(2, "Missing space after 'b'.", { character: 6 })
+ .addError(2, "Missing space after '='.", { character: 7 })
+ .addError(2, "Missing space after ')'.", { character: 18 })
+ .addError(3, "Missing space after 'd'.", { character: 6 })
+ .addError(4, "Missing space after ')'.", { character: 13 })
+ .addError(5, "Missing space after '1'.", { character: 13 })
+ .addError(7, "Missing space after '2'.", { character: 10 })
+ .addError(7, "Missing space after '+'.", { character: 11 })
+ .addError(8, "Missing space after '/'.", { character: 14 })
+ .addError(8, "Missing space after '+'.", { character: 15 })
+ .addError(8, "Missing space after 'uid'.", { character: 20 })
+ .addError(8, "Missing space after '+'.", { character: 21 })
+ .addError(8, "Missing space after '/likes?access_token='.", { character: 43 })
+ .addError(8, "Missing space after '+'.", { character: 44 })
+ .test(src, { white: true });
+
+ test.done();
};
exports.functionScopedOptions = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/functionScopedOptions.js', 'utf8');
- TestRun(test)
- .addError(1, "eval is evil.")
- .addError(8, "eval is evil.")
- .test(src);
+ var src = fs.readFileSync(__dirname + '/fixtures/functionScopedOptions.js', 'utf8');
+ TestRun(test)
+ .addError(1, "eval is evil.")
+ .addError(8, "eval is evil.")
+ .test(src);
- test.done();
+ test.done();
};
/** JSHint should not only read jshint, but also jslint options */
exports.jslintOptions = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/jslintOptions.js', 'utf8');
- TestRun(test).test(src);
+ var src = fs.readFileSync(__dirname + '/fixtures/jslintOptions.js', 'utf8');
+ TestRun(test).test(src);
- test.done();
+ test.done();
};
exports.jslintInverted = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/jslintInverted.js', 'utf8');
- TestRun(test).test(src);
+ var src = fs.readFileSync(__dirname + '/fixtures/jslintInverted.js', 'utf8');
+ TestRun(test).test(src);
- test.done();
+ test.done();
};
exports.jslintRenamed = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/jslintRenamed.js', 'utf8');
- TestRun(test)
- .addError(4, "Expected '===' and instead saw '=='.")
- .test(src);
+ var src = fs.readFileSync(__dirname + '/fixtures/jslintRenamed.js', 'utf8');
+ TestRun(test)
+ .addError(4, "Expected '===' and instead saw '=='.")
+ .test(src);
- test.done();
+ test.done();
};
exports.caseExpressions = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/caseExpressions.js', 'utf8');
- TestRun(test)
- .addError(2, "This 'switch' should be an 'if'.")
- .test(src);
+ var src = fs.readFileSync(__dirname + '/fixtures/caseExpressions.js', 'utf8');
+ TestRun(test)
+ .addError(2, "This 'switch' should be an 'if'.")
+ .test(src);
- test.done();
+ test.done();
};
exports.returnStatement = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/return.js', 'utf8');
+ var src = fs.readFileSync(__dirname + '/fixtures/return.js', 'utf8');
- TestRun(test)
- .addError(3, "Did you mean to return a conditional instead of an assignment?")
- .addError(38, "Line breaking error 'return'.")
- .test(src, { maxerr: 2 });
+ TestRun(test)
+ .addError(3, "Did you mean to return a conditional instead of an assignment?")
+ .addError(38, "Line breaking error 'return'.")
+ .test(src, { maxerr: 2 });
- test.done();
+ test.done();
};
exports.globalDeclarations = function (test) {
- var src = 'exports = module.exports = function (test) {};';
+ var src = 'exports = module.exports = function (test) {};';
- // Test should pass
- TestRun(test).test(src, { node: true }, { exports: true });
+ // Test should pass
+ TestRun(test).test(src, { node: true }, { exports: true });
- // Test should pass as well
- src = [
- '/*jshint node:true */',
- '/*global exports:true */',
- 'exports = module.exports = function (test) {};'
- ];
+ // Test should pass as well
+ src = [
+ '/*jshint node:true */',
+ '/*global exports:true */',
+ 'exports = module.exports = function (test) {};'
+ ];
- TestRun(test).test(src.join('\n'));
+ TestRun(test).test(src.join('\n'));
- test.done();
+ test.done();
};
exports.argsInCatchReused = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/trycatch.js', 'utf8');
- TestRun(test)
- .addError(6, "'e' is already defined.")
- .addError(12, "Do not assign to the exception parameter.")
- .addError(23, "'e' is not defined.")
- .test(src, { undef: true });
+ var src = fs.readFileSync(__dirname + '/fixtures/trycatch.js', 'utf8');
+ TestRun(test)
+ .addError(6, "'e' is already defined.")
+ .addError(12, "Do not assign to the exception parameter.")
+ .addError(23, "'e' is not defined.")
+ .test(src, { undef: true });
- test.done();
+ test.done();
};
exports.testRawOnError = function (test) {
- JSHINT(';', { maxerr: 1 });
- test.equal(JSHINT.errors[0].raw, 'Unnecessary semicolon.');
- test.equal(JSHINT.errors[1].raw, 'Too many errors.');
- test.equal(JSHINT.errors[2], null);
+ JSHINT(';', { maxerr: 1 });
+ test.equal(JSHINT.errors[0].raw, 'Unnecessary semicolon.');
+ test.equal(JSHINT.errors[1].raw, 'Too many errors.');
+ test.equal(JSHINT.errors[2], null);
- test.done();
+ test.done();
};
exports.yesEmptyStmt = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/emptystmt.js', 'utf8');
+ var src = fs.readFileSync(__dirname + '/fixtures/emptystmt.js', 'utf8');
- TestRun(test)
- .addError(1, "Expected an identifier and instead saw ';'.")
- .addError(6, "Expected an assignment or function call and instead saw an expression.")
- .addError(10, "Unnecessary semicolon.")
- .addError(17, "Unnecessary semicolon.")
- .test(src, { curly: false });
+ TestRun(test)
+ .addError(1, "Expected an identifier and instead saw ';'.")
+ .addError(6, "Expected an assignment or function call and instead saw an expression.")
+ .addError(10, "Unnecessary semicolon.")
+ .addError(17, "Unnecessary semicolon.")
+ .test(src, { curly: false });
- TestRun(test)
- .addError(1, "Expected an identifier and instead saw ';'.")
- .addError(10, "Unnecessary semicolon.")
- .addError(17, "Unnecessary semicolon.")
- .test(src, { curly: false, expr: true });
+ TestRun(test)
+ .addError(1, "Expected an identifier and instead saw ';'.")
+ .addError(10, "Unnecessary semicolon.")
+ .addError(17, "Unnecessary semicolon.")
+ .test(src, { curly: false, expr: true });
- test.done();
+ test.done();
};
exports.insideEval = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/insideEval.js', 'utf8');
+ var src = fs.readFileSync(__dirname + '/fixtures/insideEval.js', 'utf8');
- TestRun(test)
- .addError(1, "eval is evil.")
- .addError(3, "eval is evil.")
- .addError(5, "eval is evil.")
- .addError(7, "eval is evil.")
- .addError(9, "eval is evil.")
- .addError(11, "Implied eval is evil. Pass a function instead of a string.")
- .addError(13, "Implied eval is evil. Pass a function instead of a string.")
- .addError(15, "Implied eval is evil. Pass a function instead of a string.")
- .addError(17, "Implied eval is evil. Pass a function instead of a string.")
+ TestRun(test)
+ .addError(1, "eval is evil.")
+ .addError(3, "eval is evil.")
+ .addError(5, "eval is evil.")
+ .addError(7, "eval is evil.")
+ .addError(9, "eval is evil.")
+ .addError(11, "Implied eval is evil. Pass a function instead of a string.")
+ .addError(13, "Implied eval is evil. Pass a function instead of a string.")
+ .addError(15, "Implied eval is evil. Pass a function instead of a string.")
+ .addError(17, "Implied eval is evil. Pass a function instead of a string.")
- // The "TestRun" class (and these errors) probably needs some
- // facility for checking the expected scope of the error
- .addError(1, "Unexpected early end of program.")
- .addError(1, "Expected an identifier and instead saw '(end)'.")
- .addError(1, "Expected ')' and instead saw ''.")
- .addError(1, "Missing semicolon.")
+ // The "TestRun" class (and these errors) probably needs some
+ // facility for checking the expected scope of the error
+ .addError(1, "Unexpected early end of program.")
+ .addError(1, "Expected an identifier and instead saw '(end)'.")
+ .addError(1, "Expected ')' and instead saw ''.")
+ .addError(1, "Missing semicolon.")
- .test(src, { evil: false });
+ .test(src, { evil: false });
- test.done();
+ test.done();
};
// Regression test for GH-394.
exports.noExcOnTooManyUndefined = function (test) {
- var code = 'a(); b();';
+ var code = 'a(); b();';
- try {
- JSHINT(code, {undef: true, maxerr: 1});
- } catch (e) {
- test.ok(false, 'Exception was thrown');
- }
+ try {
+ JSHINT(code, {undef: true, maxerr: 1});
+ } catch (e) {
+ test.ok(false, 'Exception was thrown');
+ }
- TestRun(test)
- .addError(1, "'a' is not defined.")
- .test(code, { undef: true, maxerr: 1 });
+ TestRun(test)
+ .addError(1, "'a' is not defined.")
+ .test(code, { undef: true, maxerr: 1 });
- test.done();
+ test.done();
};
exports.defensiveSemicolon = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/gh-226.js', 'utf8');
+ var src = fs.readFileSync(__dirname + '/fixtures/gh-226.js', 'utf8');
- TestRun(test)
- .addError(16, "Unnecessary semicolon.")
- .addError(17, "Unnecessary semicolon.")
- .test(src, { expr: true, laxbreak: true });
+ TestRun(test)
+ .addError(16, "Unnecessary semicolon.")
+ .addError(17, "Unnecessary semicolon.")
+ .test(src, { expr: true, laxbreak: true });
- test.done();
+ test.done();
};
// Test different variants of IIFE
exports.iife = function (test) {
- var iife = [
- '(function (test) { return; }());',
- '(function (test) { return; })();'
- ];
+ var iife = [
+ '(function (test) { return; }());',
+ '(function (test) { return; })();'
+ ];
- TestRun(test).test(iife.join('\n'));
+ TestRun(test).test(iife.join('\n'));
- test.done();
+ test.done();
};
// Tests invalid options when they're passed as function arguments
// For code that tests /*jshint ... */ see parser.js
exports.invalidOptions = function (test) {
- TestRun(test)
- .addError(0, "Bad option: 'invalid'.")
- .test("function test() {}", { devel: true, invalid: true });
+ TestRun(test)
+ .addError(0, "Bad option: 'invalid'.")
+ .test("function test() {}", { devel: true, invalid: true });
- test.done();
+ test.done();
};
exports.multilineArray = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/gh-334.js', 'utf8');
+ var src = fs.readFileSync(__dirname + '/fixtures/gh-334.js', 'utf8');
- TestRun(test).test(src);
+ TestRun(test).test(src);
- test.done();
+ test.done();
};
exports.testInvalidSource = function (test) {
- TestRun(test)
- .addError(0, "Input is neither a string nor an array of strings.")
- .test(undefined);
+ TestRun(test)
+ .addError(0, "Input is neither a string nor an array of strings.")
+ .test(undefined);
- TestRun(test)
- .addError(0, "Input is neither a string nor an array of strings.")
- .test(null);
+ TestRun(test)
+ .addError(0, "Input is neither a string nor an array of strings.")
+ .test(null);
- TestRun(test)
- .addError(0, "Input is neither a string nor an array of strings.")
- .test({});
+ TestRun(test)
+ .addError(0, "Input is neither a string nor an array of strings.")
+ .test({});
- TestRun(test)
- .addError(0, "Input is an empty string.")
- .test("");
+ TestRun(test)
+ .addError(0, "Input is an empty string.")
+ .test("");
- TestRun(test)
- .addError(0, "Input is an empty array.")
- .test([]);
+ TestRun(test)
+ .addError(0, "Input is an empty array.")
+ .test([]);
- test.done();
+ test.done();
};
exports.testConstructor = function (test) {
- var code = "new Number(5);";
+ var code = "new Number(5);";
- TestRun(test)
- .addError(1, "Do not use Number as a constructor.", {
- character: 1
- })
- .test(code);
+ TestRun(test)
+ .addError(1, "Do not use Number as a constructor.", {
+ character: 1
+ })
+ .test(code);
- test.done();
+ test.done();
};
exports.missingRadix = function (test) {
- var code = "parseInt(20);";
+ var code = "parseInt(20);";
- TestRun(test)
- .addError(1, "Missing radix parameter.", {
- character: 12
- })
- .test(code);
+ TestRun(test)
+ .addError(1, "Missing radix parameter.", {
+ character: 12
+ })
+ .test(code);
- test.done();
+ test.done();
};
exports.NumberNaN = function (test) {
- var code = "(function (test) { return Number.NaN; })();";
- TestRun(test).test(code);
+ var code = "(function (test) { return Number.NaN; })();";
+ TestRun(test).test(code);
- test.done();
+ test.done();
};
exports.htmlEscapement = function (test) {
- TestRun(test).test("var a = '<\\!--';");
- TestRun(test)
- .addError(1, "Bad escapement.")
- .test("var a = '\\!';");
+ TestRun(test).test("var a = '<\\!--';");
+ TestRun(test)
+ .addError(1, "Bad escapement.")
+ .test("var a = '\\!';");
- test.done();
+ test.done();
};
// GH-551 regression test.
exports.testSparseArrays = function (test) {
- var src = "var arr = ['a',, null,, '',, undefined,,];";
+ var src = "var arr = ['a',, null,, '',, undefined,,];";
- TestRun(test)
- .addError(1, "Extra comma.")
- .addError(1, "Extra comma.")
- .addError(1, "Extra comma.")
- .addError(1, "Extra comma.")
- .test(src);
+ TestRun(test)
+ .addError(1, "Extra comma.")
+ .addError(1, "Extra comma.")
+ .addError(1, "Extra comma.")
+ .addError(1, "Extra comma.")
+ .test(src);
- TestRun(test)
- .test(src, { es5: true });
+ TestRun(test)
+ .test(src, { es5: true });
- test.done();
+ test.done();
};
exports.testCatchBlocks = function (test) {
- var src = fs.readFileSync(__dirname + '/fixtures/gh247.js', 'utf8');
+ var src = fs.readFileSync(__dirname + '/fixtures/gh247.js', 'utf8');
- TestRun(test)
- .addError(11, "'w' is not defined.")
- .test(src, { undef: true, devel: true });
+ TestRun(test)
+ .addError(11, "'w' is not defined.")
+ .test(src, { undef: true, devel: true });
- src = fs.readFileSync(__dirname + '/fixtures/gh618.js', 'utf8');
+ src = fs.readFileSync(__dirname + '/fixtures/gh618.js', 'utf8');
- TestRun(test)
- .addError(5, "Value of 'x' may be overwritten in IE.")
- .test(src, { undef: true, devel: true });
+ TestRun(test)
+ .addError(5, "Value of 'x' may be overwritten in IE.")
+ .test(src, { undef: true, devel: true });
- TestRun(test)
- .test(src, { undef: true, devel: true, node: true });
+ TestRun(test)
+ .test(src, { undef: true, devel: true, node: true });
- test.done();
+ test.done();
};
exports.testNumericParams = function (test) {
- TestRun(test)
- .test("/*jshint maxparams:4, indent:3 */");
+ TestRun(test)
+ .test("/*jshint maxparams:4, indent:3 */");
- TestRun(test)
- .addError(1, "Expected a small integer and instead saw 'face'.")
- .test("/*jshint maxparams:face */");
+ TestRun(test)
+ .addError(1, "Expected a small integer and instead saw 'face'.")
+ .test("/*jshint maxparams:face */");
- test.done();
+ test.done();
};
View
1,066 tests/stable/unit/envs.js
@@ -4,194 +4,194 @@
"use strict";
-var JSHINT = require('../../../src/stable/jshint.js').JSHINT;
-var fs = require('fs');
+var JSHINT = require('../../../src/stable/jshint.js').JSHINT;
+var fs = require('fs');
var TestRun = require("../helpers/testhelper").setup.testRun;
function wrap(globals) {
- return '(function () { return [ ' + globals.join(',') + ' ]; }());';
+ return '(function () { return [ ' + globals.join(',') + ' ]; }());';
}
function globalsKnown(test, globals, options) {
- JSHINT(wrap(globals), options || {});
- var report = JSHINT.data();
+ JSHINT(wrap(globals), options || {});
+ var report = JSHINT.data();
- test.ok(report.implied === undefined);
- test.equal(report.globals.length, globals.length);
+ test.ok(report.implied === undefined);
+ test.equal(report.globals.length, globals.length);
- for (var i = 0, g; g = report.globals[i]; i += 1)
- globals[g] = true;
+ for (var i = 0, g; g = report.globals[i]; i += 1)
+ globals[g] = true;
- for (i = 0, g = null; g = globals[i]; i += 1)
- test.ok(g in globals);
+ for (i = 0, g = null; g = globals[i]; i += 1)
+ test.ok(g in globals);
}
function globalsImplied(test, globals, options) {
- JSHINT(wrap(globals), options || {});
- var report = JSHINT.data();
+ JSHINT(wrap(globals), options || {});
+ var report = JSHINT.data();
- test.ok(report.implieds !== null);
- test.ok(report.globals === undefined);
+ test.ok(report.implieds !== null);
+ test.ok(report.globals === undefined);
- var implieds = [];
- for (var i = 0, warn; warn = report.implieds[i]; i += 1)
- implieds.push(warn.name);
+ var implieds = [];
+ for (var i = 0, warn; warn = report.implieds[i]; i += 1)
+ implieds.push(warn.name);
- test.equal(implieds.length, globals.length);
+ test.equal(implieds.length, globals.length);
}
/*
* Option `node` predefines Node.js (v 0.5.9) globals
*
* More info:
- * + http://nodejs.org/docs/v0.5.9/api/globals.html
+ * + http://nodejs.org/docs/v0.5.9/api/globals.html
*/
exports.node = function (test) {
- var globals = [
- "__filename",
- "__dirname",
- "Buffer",
- "GLOBAL",
- "global",
- "module",
- "process",
- "require",
- "exports",
- "console",
- "setTimeout",
- "clearTimeout",
- "setInterval",
- "clearInterval"
- ];
-
- globalsImplied(test, globals);
- globalsKnown(test, globals, { node: true });
-
- // Make sure that the `node` option doesn't conflict with `nomen`
- var asGlobals = [
- 'console.log(__dirname);',
- "console.log(__filename);",
- ];
-
- var asProps = [
- 'console.log(a.__dirname);',
- 'console.log(a.__filename);',
- "console.log(__hello);",
- ];
-
- TestRun(test).test(asGlobals, { node: true, nomen: true });
- TestRun(test)
- .addError(1, "Unexpected dangling '_' in '__dirname'.")
- .addError(2, "Unexpected dangling '_' in '__filename'.")
- .addError(3, "Unexpected dangling '_' in '__hello'.")
- .test(asProps, { node: true, nomen: true });
-
- // Node environment assumes `globalstrict`
- var globalStrict = [
- '"use strict";',
- "function test() { return; }",
- ].join('\n');
-
- TestRun(test)
- .addError(1, 'Use the function form of "use strict".')
- .test(globalStrict);
-
- TestRun(test)
- .test(globalStrict, { node: true });
-
- // Make sure that we can do fancy Node export
-
- var overwrites = [
- "Buffer = {};",
- "exports = module.exports = {};"
- ];
-
- TestRun(test)
- .addError(1, "Read only.")
- .test(overwrites, { node: true });
-
- test.done();
+ var globals = [
+ "__filename",
+ "__dirname",
+ "Buffer",
+ "GLOBAL",
+ "global",
+ "module",
+ "process",
+ "require",
+ "exports",
+ "console",
+ "setTimeout",
+ "clearTimeout",
+ "setInterval