Skip to content
This repository has been archived by the owner on Sep 17, 2018. It is now read-only.

Update JSLint to douglascrockford/JSLint@4f2bf65 #35

Merged
merged 5 commits into from
Aug 21, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- 0.4
- 0.5
- 0.6
- 0.7
73 changes: 37 additions & 36 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,44 @@
* Options support added by Corey Hart <corey@codenothing.com>
*/

/*jslint indent: 4*/

var options = {
"adsafe" : false, // if ADsafe should be enforced
"bitwise" : true, // if bitwise operators should not be allowed
"browser" : false, // if the standard browser globals should be predefined
"cap" : false, // if upper case HTML should be allowed
"confusion" : false, // if types can be used inconsistently
"continue" : true, // if the continuation statement should be tolerated
"css" : false, // if CSS workarounds should be tolerated
"debug" : false, // if debugger statements should be allowed
"devel" : false, // if logging should be allowed (console, alert, etc.)
"eqeq" : false, // if the == should be allowed
"es5" : true, // if ES5 syntax should be allowed
"evil" : false, // if eval should be allowed
"forin" : true, // if for in statements need not filter
"fragment" : false, // if HTML fragments should be allowed
"indent" : 2, // set the expected indentation level
"maxerr" : 50, // the maximum number of errors to allow
"maxlen" : 100, // the maximum length of a source line
"newcap" : false, // if constructor names capitalization is ignored
"node" : true, // if Node.js globals should be predefined
"nomen" : true, // true, if names may have dangling _
"on" : false, // if HTML event handlers should be allowed
"passfail" : false, // if the scan should stop on first error
"plusplus" : false, // if increment/decrement should be allowed
"properties" : false, // if all property names must be declared with /*properties*/
"regexp" : true, // if the . should be allowed in regexp literals
"rhino" : false, // if the Rhino environment globals should be predefined
"undef" : false, // if variables can be declared out of order
"unparam" : true, // if unused parameters should be tolerated
"safe" : false, // if use of some browser features should be restricted
"sloppy" : true, // if the 'use strict'; pragma is optional
"sub" : false, // if all forms of subscript notation are tolerated
"vars" : false, // if multiple var statements per function should be allowed
"white" : true, // if sloppy whitespace is tolerated
"widget" : false, // if the Yahoo Widgets globals should be predefined
"windows" : false, // if MS Windows-specific globals should be predefined
anon: false, // if the space may be omitted in anonymous function declarations
bitwise: true, // if bitwise operators should be allowed
browser: false, // if the standard browser globals should be predefined
cap: false, // if upper case HTML should be allowed
'continue': false, // if the continuation statement should be tolerated
css: false, // if CSS workarounds should be tolerated
debug: false, // if debugger statements should be allowed
devel: false, // if logging should be allowed (console, alert, etc.)
eqeq: false, // if == should be allowed
es5: false, // if ES5 syntax should be allowed
evil: false, // if eval should be allowed
forin: false, // if for in statements need not filter
fragment: false, // if HTML fragments should be allowed
indent: 2, // the indentation factor
maxerr: 50, // the maximum number of errors to allow
maxlen: 100, // the maximum length of a source line
newcap: false, // if constructor names capitalization is ignored
node: true, // if Node.js globals should be predefined
nomen: true, // if names may have dangling _
on: false, // if HTML event handlers should be allowed
passfail: false, // if the scan should stop on first error
plusplus: true, // if increment/decrement should be allowed
properties: false, // if all property names must be declared with /*properties*/
regexp: true, // if the . should be allowed in regexp literals // TODO: fix this later
rhino: false, // if the Rhino environment globals should be predefined
undef: false, // if variables can be declared out of order
unparam: false, // if unused parameters should be tolerated
sloppy: true, // if the 'use strict'; pragma is optional // TODO: fix this later
stupid: true, // if really stupid practices are tolerated // TODO: fix this later
sub: false, // if all forms of subscript notation are tolerated
vars: false, // if multiple var statements per function should be allowed
white: false, // if sloppy whitespace is tolerated
widget: false, // if the Yahoo Widgets globals should be predefined
windows: false, // if MS Windows-specific globals should be predefined

// the names of predefined global variables:
"predef" : []
"predef": []
};
2 changes: 1 addition & 1 deletion jslint
16 changes: 9 additions & 7 deletions lib/reporters/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ if (process.platform !== 'win32') {
/**
* Customise the error reporting -- the following colours the text red if enableColors
*/
var errorPrefix = enableColors ? "\u001b[1;31m" : "",
errorSuffix = enableColors ? "\u001b[0m" : "";
var
errorPrefix = enableColors ? "\u001b[1;31m" : "",
errorSuffix = enableColors ? "\u001b[0m" : "";

/**
* Report linting results to the command-line.
Expand All @@ -38,11 +39,12 @@ var errorPrefix = enableColors ? "\u001b[1;31m" : "",
* @param {Array} results
*/
exports.report = function report(results) {
var error_regexp = /^\s*(\S*(\s+\S+)*)\s*$/,
i,
len = results.length,
str = '',
error;
var
error_regexp = /^\s*(\S*(\s+\S+)*)\s*$/,
i,
len = results.length,
str = '',
error;

for (i = 0; i < len; i += 1) {
error = results[i].error;
Expand Down
13 changes: 7 additions & 6 deletions lib/reporters/idea.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ exports.info = "IDEA reporter";
* @param {Array} results
*/
exports.report = function report(results) {
var error_regexp = /^\s*(\S*(\s+\S+)*)\s*$/,
i,
len = results.length,
str = '',
file,
error;
var
error_regexp = /^\s*(\S*(\s+\S+)*)\s*$/,
i,
len = results.length,
str = '',
file,
error;

if (len > 0) {
for (i = 0; i < len; i += 1) {
Expand Down
21 changes: 11 additions & 10 deletions lib/reporters/textmate_full.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ exports.info = "Textmate full HTML reporter";
* @param {Array} results
*/
exports.report = function report(results) {
var error_regexp = /^\s*(\S*(\s+\S+)*)\s*$/,
i,
len = results.length,
output = '',
html = '',
file,
error,
reason,
line,
character;
var
error_regexp = /^\s*(\S*(\s+\S+)*)\s*$/,
i,
len = results.length,
output = '',
html = '',
file,
error,
reason,
line,
character;

for (i = 0; i < len; i += 1) {
file = results[i].file;
Expand Down
27 changes: 13 additions & 14 deletions lib/reporters/textmate_summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ exports.info = "Textmate full HTML reporter";
* @param {Array} results
*/
exports.report = function report(results) {
var len = results.length,
output = '',

printer = {
getOutput: function () {
var error_regexp = /^\s*(\S*(\s+\S+)*)\s*$/,
i,
len = results.length,
output = '',
file,
error;
var
len = results.length,
output = '',
getOutput = function () {
var
error_regexp = /^\s*(\S*(\s+\S+)*)\s*$/,
i,
len = results.length,
output = '',
file,
error;

for (i = 0; i < len; i += 1) {
file = results[i].file;
Expand All @@ -61,11 +61,10 @@ exports.report = function report(results) {
(error.evidence || '').replace(error_regexp, "$1") + '\n\n';
}
return output;
}
};
};

if (len > 0 && len < 2) {
output += printer.getOutput(results);
output += getOutput();
}
output += len + ' error' + ((len === 1) ? '' : 's');

Expand Down
13 changes: 7 additions & 6 deletions lib/reporters/vim.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ exports.info = "VIM syntastic reporter";
* @param {Array} results
*/
exports.report = function report(results) {
var error_regexp = /^\s*(\S*(\s+\S+)*)\s*$/,
i,
len = results.length,
str = '',
file,
error;
var
error_regexp = /^\s*(\S*(\s+\S+)*)\s*$/,
i,
len = results.length,
str = '',
file,
error;

if (len > 0) {
for (i = 0; i < len; i += 1) {
Expand Down
12 changes: 7 additions & 5 deletions lib/reporters/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
/**
* Module dependencies
*/
var path = require('path'),
util = require('util');
var
path = require('path'),
util = require('util');

/**
* Reporter info string
Expand All @@ -36,9 +37,10 @@ function escape(str) {
* @param {Array} results
*/
exports.report = function report(results) {
var i, error, len, file,
dir = process.cwd(),
xml = '<?xml version="1.0" encoding="UTF-8" ?>\n<jslint>\n';
var
i, error, len, file,
dir = process.cwd(),
xml = '<?xml version="1.0" encoding="UTF-8" ?>\n<jslint>\n';

for (i = 0, len = results.length; i < len; i += 1) {
file = path.resolve(dir, results[i].file);
Expand Down
85 changes: 45 additions & 40 deletions nodelint
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,29 @@
/*jslint evil: true */

(function () {
var f = require('file'),
fs = require('fs'),
path = require('path'),
util = require('util'),
SCRIPT_DIRECTORY,
DEFAULT_CONFIG_FILE,
params,
files,
config_file,
config_param_found,
reporter_file = 'default',
reporter_param_found,
builtin_reporters = require(__dirname + '/lib/reporters'),
reporter,
usage = "Usage: nodelint file.js [file2 file3 ...] [options]\n" +
"Options:\n\n" +
" --config FILE the path to a config.js file with JSLINT options\n" +
" --reporter FILE optional path to a reporter.js file to customize the output\n" +
" --list-reporters list available build-in reporters\n" +
" -h, --help display this help and exit\n" +
" -v, --version output version information and exit";
var
f = require('file'),
fs = require('fs'),
path = require('path'),
util = require('util'),
SCRIPT_DIRECTORY,
DEFAULT_CONFIG_FILE,
params,
files,
config_file,
config_param_found,
reporter_file = 'default',
reporter_param_found,
builtin_reporters = require(__dirname + '/lib/reporters'),
reporter,
usage =
"Usage: nodelint file.js [file2 file3 ...] [options]\n" +
"Options:\n\n" +
" --config FILE the path to a config.js file with JSLINT options\n" +
" --reporter FILE optional path to a reporter.js file to customize the output\n" +
" --list-reporters list available build-in reporters\n" +
" -h, --help display this help and exit\n" +
" -v, --version output version information and exit";

// -----------------------------------------------------------------------------
// load jslint itself and set the path to the default config file
Expand All @@ -48,10 +50,11 @@
// -----------------------------------------------------------------------------

function lint(files, default_config_file, config_file, reporter) {
var retval = 0,
results = [],
option_name,
real_options;
var
retval = 0,
results = [],
option_name,
real_options;

if (!files.length) {
util.puts(usage);
Expand All @@ -76,18 +79,19 @@
}

for (option_name in options) {
if (typeof option_name === 'string') {
if (options.hasOwnProperty(option_name)) {
real_options[option_name] = options[option_name];
}
}
}

files.forEach(function (file) {
var source,
i,
error,
// Quite enougth config clone, may be improved in future
current_file_options = JSON.parse(JSON.stringify(real_options));
var
source,
i,
error,
// Quite enougth config clone, may be improved in future
current_file_options = JSON.parse(JSON.stringify(real_options));

try {
source = fs.readFileSync(file, 'utf8');
Expand Down Expand Up @@ -144,17 +148,18 @@
} else if (param === '--list-reporters') {
util.puts('Build-in reporters: ');
for (reporter_file_for_forin_loop in builtin_reporters) {
if (builtin_reporters[reporter_file_for_forin_loop].info) {
util.puts(' * ' + reporter_file_for_forin_loop
+ ': ' + builtin_reporters[reporter_file_for_forin_loop].info);
} else {
util.puts(' * ' + reporter_file_for_forin_loop);
if (builtin_reporters.hasOwnProperty(reporter_file_for_forin_loop)) {
if (builtin_reporters[reporter_file_for_forin_loop].info) {
util.puts(' * ' + reporter_file_for_forin_loop
+ ': ' + builtin_reporters[reporter_file_for_forin_loop].info);
} else {
util.puts(' * ' + reporter_file_for_forin_loop);
}
}
}
process.exit(0);
} else if ((param === '--version') || (param === '-v')) {
content = fs.readFileSync(
path.join(SCRIPT_DIRECTORY, 'package.json'), 'utf8');
content = fs.readFileSync(path.join(SCRIPT_DIRECTORY, 'package.json'), 'utf8');
pkg = JSON.parse(content);
util.puts(pkg.version);
process.exit(0);
Expand All @@ -179,9 +184,9 @@

// Get reporter by name or by file
if (builtin_reporters.hasOwnProperty(reporter_file)) {
reporter = builtin_reporters[reporter_file];
reporter = builtin_reporters[reporter_file];
} else {
reporter = require(reporter_file);
reporter = require(reporter_file);
}

process.exit(lint(files, DEFAULT_CONFIG_FILE, config_file, reporter));
Expand Down
5 changes: 3 additions & 2 deletions test/fixtures/some-errors.js.nolint
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var a = 1,
b = 2;
var
a = 1,
b = 2;

if (a = b) {
console.log("Hehe");
Expand Down
Loading