This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

updating to nodelint 0.5.0, fixing config and errors

  • Loading branch information...
paularmstrong committed Sep 24, 2011
1 parent 8587b90 commit 46d313faef9b1d2a888b61185043043af3c4a6d7
Showing with 164 additions and 135 deletions.
  1. +15 −13 examples/custom_tags/custom_tags.js
  2. +14 −14 index.js
  3. +1 −1 lib/dateformat.js
  4. +2 −1 lib/filters.js
  5. +2 −2 lib/helpers.js
  6. +22 −8 lib/parser.js
  7. +56 −48 lib/tags.js
  8. +1 −1 package.json
  9. +15 −13 scripts/config-lint.js
  10. +5 −2 scripts/runlint.js
  11. +8 −18 scripts/runtests.js
  12. +23 −14 tests/speed.js
@@ -9,19 +9,21 @@ exports.input = function (indent) {
value = (this.args.length > 3) ? parser.parseVariable(this.args[3]) : '',
out = [];
- out = ['(function() {'
- , helpers.setVar('__name', name)
- , helpers.setVar('__type', type)
- , helpers.setVar('__label', label)
- , helpers.setVar('__value', value)
- , ' __output.push(\'<div class="input \' + __type + \'">\')'
- , ' __output.push(\'\\n\')'
- , ' __output.push(\'<label for="\' + __name + \'">\' + __label + \'</label>\');'
- , ' __output.push(\'<input type="\' + __type + \'" name="\' + __name + \'" id="\' + __name + \'" value="\' + __value + \'">\');'
- , ' __output.push(\'\\n\')'
- , ' __output.push("</div>")'
- , ' __output.push(\'\\n\')'
- , '})();'];
+ out = [
+ '(function() {',
+ helpers.setVar('__name', name),
+ helpers.setVar('__type', type),
+ helpers.setVar('__label', label),
+ helpers.setVar('__value', value),
+ ' __output.push(\'<div class="input \' + __type + \'">\')',
+ ' __output.push(\'\\n\')',
+ ' __output.push(\'<label for="\' + __name + \'">\' + __label + \'</label>\');',
+ ' __output.push(\'<input type="\' + __type + \'" name="\' + __name + \'" id="\' + __name + \'" value="\' + __value + \'">\');',
+ ' __output.push(\'\\n\')',
+ ' __output.push("</div>")',
+ ' __output.push(\'\\n\')',
+ '})();'
+ ];
return out.join('\n' + indent);
};
View
@@ -60,23 +60,23 @@ function createTemplate(data, id) {
code = parser.compile.call(template);
// The compiled render function - this is all we need
- render = new Function('__context', '__parents', '__filters', '__escape',
- [ '__parents = __parents ? __parents.slice() : [];'
+ render = new Function('__context', '__parents', '__filters', '__escape', [
+ '__parents = __parents ? __parents.slice() : [];',
// Prevents circular includes (which will crash node without warning)
- , 'var j = __parents.length,'
- , ' __output = [],'
- , ' __this = this;'
+ 'var j = __parents.length,',
+ ' __output = [],',
+ ' __this = this;',
// Note: this loop averages much faster than indexOf across all cases
- , 'while (j--) {'
- , ' if (__parents[j] === this.id) {'
- , ' return "Circular import of template " + this.id + " in " + __parents[__parents.length-1];'
- , ' }'
- , '}'
+ 'while (j--) {',
+ ' if (__parents[j] === this.id) {',
+ ' return "Circular import of template " + this.id + " in " + __parents[__parents.length-1];',
+ ' }',
+ '}',
// Add this template as a parent to all includes in its scope
- , '__parents.push(this.id);'
- , code
- , 'return __output.join("");'].join('')
- );
+ '__parents.push(this.id);',
+ code,
+ 'return __output.join("");',
+ ].join(''));
template.render = function (context, parents) {
if (config.allowErrors) {
View
@@ -57,7 +57,7 @@ var _dateFormats = module.exports = {
return input.getFullYear();
},
y: function (input) {
- return ('' + input.getFullYear()).substr(2);
+ return (input.getFullYear().toString()).substr(2);
},
// Time
View
@@ -32,7 +32,8 @@ exports.capitalize = function (input) {
exports.date = function (input, format) {
var l = format.length,
date = new Date(input),
- cur, i = 0,
+ cur,
+ i = 0,
out = '';
for (; i < l; i += 1) {
View
@@ -19,7 +19,7 @@ function isLiteral(string) {
// Check if it's a valid string literal (throw exception otherwise)
teststr = string.substr(1, string.length - 2).split('').reverse().join('');
- if (string[0] === "'" && UNESCAPED_QUOTE.test(teststr) || string[1] === '"' && UNESCAPED_DQUOTE.test(teststr)) {
+ if ((string[0] === "'" && UNESCAPED_QUOTE.test(teststr)) || (string[1] === '"' && UNESCAPED_DQUOTE.test(teststr))) {
throw new Error('Invalid string literal. Unescaped quote (' + string[0] + ') found.');
}
@@ -36,7 +36,7 @@ function isStringLiteral(string) {
if ((string[0] === string[string.length - 1]) && (string[0] === "'" || string[0] === '"')) {
var teststr = string.substr(1, string.length - 2).split('').reverse().join('');
- if (string[0] === "'" && UNESCAPED_QUOTE.test(teststr) || string[1] === '"' && UNESCAPED_DQUOTE.test(teststr)) {
+ if ((string[0] === "'" && UNESCAPED_QUOTE.test(teststr)) || (string[1] === '"' && UNESCAPED_DQUOTE.test(teststr))) {
throw new Error('Invalid string literal. Unescaped quote (' + string[0] + ') found.');
}
View
@@ -62,7 +62,9 @@ function parseVariable(token, escape) {
var filters = [],
parts = token.replace(/^\{\{ *| *\}\}$/g, '').split('|'),
varname = parts.shift(),
- args = null, filter_name, part;
+ args = null,
+ filter_name,
+ part;
if ((/\(/).test(varname)) {
args = getArgs(varname);
@@ -101,9 +103,18 @@ exports.parse = function (data, tags, autoescape) {
last_escape = escape,
stack = [[]],
index = 0,
- i = 0, j = rawtokens.length,
- filters = [], filter_name,
- varname, token, parts, part, names, matches, tagname, lastToken;
+ i = 0,
+ j = rawtokens.length,
+ filters = [],
+ filter_name,
+ varname,
+ token,
+ parts,
+ part,
+ names,
+ matches,
+ tagname,
+ lastToken;
for (; i < j; i += 1) {
token = rawtokens[i];
@@ -126,14 +137,14 @@ exports.parse = function (data, tags, autoescape) {
escape = last_escape;
}
stack.pop();
- index--;
+ index -= 1;
continue;
}
throw new Error('Unbalanced end tag found: ' + tagname);
}
- if (!(tagname in tags)) {
+ if (!tags.hasOwnProperty(tagname)) {
throw new Error('Unknown logic tag: ' + tagname);
}
@@ -153,7 +164,7 @@ exports.parse = function (data, tags, autoescape) {
if (tags[tagname].ends) {
stack[index].push(token);
stack.push(token.tokens = []);
- index++;
+ index += 1;
continue;
}
}
@@ -172,7 +183,10 @@ exports.parse = function (data, tags, autoescape) {
exports.compile = function compile(indent, parentBlock) {
var code = [''],
tokens = [],
- parent, filepath, blockname, varOutput;
+ parent,
+ filepath,
+ blockname,
+ varOutput;
indent = indent || '';
View
@@ -31,20 +31,22 @@ exports.include = function (indent) {
}
// Circular includes are VERBOTTEN. This will crash the server.
- return ['(function () {'
- , ' if (' + helpers.check(template) + ') {'
- , ' var __template = ' + helpers.escape(template) + ';'
- , ' }'
- , ' else if (' + helpers.check(template, '__context') + ') {'
- , ' var __template = ' + helpers.escape(template, '__context') + ';'
- , ' }'
- , ' if (typeof __template === "string") {'
- , ' __output.push(__this.fromFile(__template).render(__context, __parents));'
- , ' }'
- , ' else if (typeof __template === "object" && __template.render) {'
- , ' __output.push(__template.render(__context, __parents));'
- , ' }'
- , '})();'].join('\n' + indent);
+ return [
+ '(function () {',
+ ' if (' + helpers.check(template) + ') {',
+ ' var __template = ' + helpers.escape(template) + ';',
+ ' }',
+ ' else if (' + helpers.check(template, '__context') + ') {',
+ ' var __template = ' + helpers.escape(template, '__context') + ';',
+ ' }',
+ ' if (typeof __template === "string") {',
+ ' __output.push(__this.fromFile(__template).render(__context, __parents));',
+ ' }',
+ ' else if (typeof __template === "object" && __template.render) {',
+ ' __output.push(__template.render(__context, __parents));',
+ ' }',
+ '})();'
+ ].join('\n' + indent);
};
function checkIfArgs(leftOperand, operator, rightOperand) {
@@ -126,7 +128,11 @@ exports.else = function (indent) {
}
var ifarg = this.args.shift(),
- leftOperand, operator, rightOperand, negation, out;
+ leftOperand,
+ operator,
+ rightOperand,
+ negation,
+ out;
if (ifarg) {
leftOperand = parser.parseVariable(this.args[0]);
@@ -195,39 +201,41 @@ exports['for'] = function (indent) {
throw new Error('Invalid arguments (' + operand2.name + ') passed to "for" tag');
}
- return ['(function () {'
- , ' var ' + helpers.escape(operand1) + ','
- , ' forloop = {};'
- , helpers.setVar('__forloopIter', operand2)
- , ' else {'
- , ' return;'
- , ' }'
- , ' if (Array.isArray(__forloopIter)) {'
- , ' var __forloopIndex = 0, __forloopLength = __forloopIter.length;'
- , ' for (; __forloopIndex < __forloopLength; __forloopIndex += 1) {'
- , ' forloop.index = __forloopIndex;'
- , ' forloop.key = __forloopIndex;'
- , ' forloop.first = (__forloopIndex === 0);'
- , ' forloop.last = (__forloopIndex === __forloopLength - 1);'
- , ' ' + helpers.escape(operand1) + ' = __forloopIter[__forloopIndex];'
- , ' ' + parser.compile.call(this, indent + ' ')
- , ' }'
- , ' } else if (typeof __forloopIter === "object") {'
- , ' var __forloopKey, __forloopLength = Object.keys(__forloopIter).length, __forloopIndex = 0;'
- , ' for (__forloopKey in __forloopIter) {'
- , ' if (!__forloopIter.hasOwnProperty(__forloopKey)) {'
- , ' continue;'
- , ' }'
- , ' forloop.index = __forloopIndex;'
- , ' forloop.key = __forloopKey;'
- , ' forloop.first = (__forloopIndex === 0);'
- , ' forloop.last = (__forloopIndex === __forloopLength - 1);'
- , ' ' + helpers.escape(operand1) + ' = __forloopIter[__forloopKey];'
- , ' ' + parser.compile.call(this, indent + ' ')
- , ' __forloopIndex += 1;'
- , ' }'
- , ' }'
- , '})();'].join('\n' + indent);
+ return [
+ '(function () {',
+ ' var ' + helpers.escape(operand1) + ',',
+ ' forloop = {};',
+ helpers.setVar('__forloopIter', operand2),
+ ' else {',
+ ' return;',
+ ' }',
+ ' if (Array.isArray(__forloopIter)) {',
+ ' var __forloopIndex = 0, __forloopLength = __forloopIter.length;',
+ ' for (; __forloopIndex < __forloopLength; __forloopIndex += 1) {',
+ ' forloop.index = __forloopIndex;',
+ ' forloop.key = __forloopIndex;',
+ ' forloop.first = (__forloopIndex === 0);',
+ ' forloop.last = (__forloopIndex === __forloopLength - 1);',
+ ' ' + helpers.escape(operand1) + ' = __forloopIter[__forloopIndex];',
+ ' ' + parser.compile.call(this, indent + ' '),
+ ' }',
+ ' } else if (typeof __forloopIter === "object") {',
+ ' var __forloopKey, __forloopLength = Object.keys(__forloopIter).length, __forloopIndex = 0;',
+ ' for (__forloopKey in __forloopIter) {',
+ ' if (!__forloopIter.hasOwnProperty(__forloopKey)) {',
+ ' continue;',
+ ' }',
+ ' forloop.index = __forloopIndex;',
+ ' forloop.key = __forloopKey;',
+ ' forloop.first = (__forloopIndex === 0);',
+ ' forloop.last = (__forloopIndex === __forloopLength - 1);',
+ ' ' + helpers.escape(operand1) + ' = __forloopIter[__forloopKey];',
+ ' ' + parser.compile.call(this, indent + ' '),
+ ' __forloopIndex += 1;',
+ ' }',
+ ' }',
+ '})();'
+ ].join('\n' + indent);
};
exports['for'].ends = true;
View
@@ -13,7 +13,7 @@
},
"devDependencies": {
"express": ">=2.4.0",
- "nodelint": "0.4.0",
+ "nodelint": "0.5.0",
"nodeunit": "0.5.3"
},
"main": "index",
View
@@ -5,36 +5,38 @@ module.exports = {
var options = {
adsafe: false,
- bitwise: false,
- browser: true,
+ bitwise: true,
+ browser: false,
cap: false,
+ confusion: false,
+ continue: true,
css: false,
debug: false,
devel: true,
- eqeqeq: true,
+ eqeq: false,
+ es5: true,
evil: true,
forin: false,
fragment: false,
- immed: false,
indent: 4,
- laxbreak: true,
maxerr: 300,
maxlen: 600,
- nomen: false,
newcap: true,
node: true, // jslint.com has an option for node, but the node module is not up to date yet
- on: true,
- onevar: true,
+ nomen: true,
+ on: false,
passfail: false,
plusplus: false,
- predef: ['module', 'util', 'require', 'process', 'exports', 'escape', '__dirname', 'setTimeout'],
- regexp: false,
+ predef: [],
+ regexp: true,
rhino: false,
safe: false,
- strict: false,
+ sloppy: true,
sub: false,
- undef: true,
- white: true,
+ undef: false,
+ unparam: false,
+ vars: false,
+ white: false,
widget: false,
windows: false
};
View
@@ -2,7 +2,9 @@ var util = require('util'),
child_process = require('child_process'),
configFile = __dirname + '/config-lint',
ignore = '',
- config, root, i;
+ config,
+ root,
+ i;
process.argv.forEach(function (val, index, array) {
if (index < 2) {
@@ -25,7 +27,8 @@ function runLint(error, stdout, stderr) {
}
i = config.pathIgnore.length;
-while (i--) {
+while (i) {
+ i -= 1;
ignore += ' ! -path "' + config.pathIgnore[i] + '"';
}
Oops, something went wrong.

0 comments on commit 46d313f

Please sign in to comment.