Permalink
Browse files

Improved code style

- add jshint
- remove unuse variable
- remove node@0.8 and add iojs for travis
  • Loading branch information...
1 parent 33c2dfa commit f6e16419a54f257b9bef5994fac06d4020cdcc87 @popomore popomore committed Mar 13, 2015
View
@@ -0,0 +1,11 @@
+node_modules
+spm_modules
+coverage
+dist
+browser
+docs
+tests/express-sample
+tests/express
+tests/browser
+bench
+src/loaders.js
View
@@ -0,0 +1,31 @@
+{
+ "latedef": "nofunc",
+ "newcap": false,
+ "curly": false,
+ "eqeqeq": true,
+ "eqnull": true,
+ "strict": true,
+ "undef": true,
+ "unused": true,
+ "laxcomma": false,
+ "asi": false,
+ "boss": true,
+ "expr": true,
+ "sub": true,
+ "quotmark": true,
+ "laxbreak": true,
+ "loopfunc": false,
+ "lastsemic": true,
+ "funcscope": false,
+ "esnext": true,
+ "noyield": true,
+ "browser": true,
+ "nonstandard": true,
+ "jquery": true,
+ "devel": true,
+ "node": true,
+ "mocha": true,
+ "globals": {
+ "nunjucks": false
+ }
+}
View
@@ -1,4 +1,6 @@
language: node_js
node_js:
+ - "iojs-1"
+ - "0.12"
- "0.11"
- "0.10"
View
@@ -1,3 +1,4 @@
+'use strict';
var lib = require('./src/lib');
var env = require('./src/environment');
@@ -33,8 +34,8 @@ module.exports.configure = function(templatesPath, opts) {
}
var noWatch = 'watch' in opts ? !opts.watch : false;
- var loader = loaders.FileSystemLoader || loaders.WebLoader;
- e = new env.Environment(new loader(templatesPath, noWatch), opts);
+ var RealLoader = loaders.FileSystemLoader || loaders.WebLoader;
+ e = new env.Environment(new RealLoader(templatesPath, noWatch), opts);
if(opts && opts.express) {
e.express(opts.express);
View
@@ -14,13 +14,15 @@
"uglify-js": "*",
"express": "4.x",
"supertest": "*",
- "istanbul": "0.3.x"
+ "istanbul": "0.3.x",
+ "jshint": "*"
},
"engines": {
"node": "*"
},
"scripts": {
- "test": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- -b -R tap tests",
+ "lint": "jshint .",
+ "test": "jshint . && istanbul cover ./node_modules/mocha/bin/_mocha -- -b -R tap tests",
"browserfiles": "./bin/bundle browser/nunjucks; SLIM=1 ./bin/bundle browser/nunjucks-slim"
},
"bin": {
View
@@ -4,6 +4,7 @@ var lib = require('./lib');
var parser = require('./parser');
var transformer = require('./transformer');
var nodes = require('./nodes');
+// jshint -W079
var Object = require('./object');
var Frame = require('./runtime').Frame;
@@ -211,11 +212,9 @@ var Compiler = Object.extend({
},
compileCallExtension: function(node, frame, async) {
- var name = node.extName;
var args = node.args;
var contentArgs = node.contentArgs;
var autoescape = typeof node.autoescape === 'boolean' ? node.autoescape : true;
- var transformedArgs = [];
if(!async) {
this.emit(this.buffer + ' += runtime.suppressValue(');
@@ -294,7 +293,7 @@ var Compiler = Object.extend({
this._compileChildren(node, frame);
},
- compileLiteral: function(node, frame) {
+ compileLiteral: function(node) {
if(typeof node.value === 'string') {
var val = node.value.replace(/\\/g, '\\\\');
val = val.replace(/"/g, '\\"');
@@ -602,6 +601,7 @@ var Compiler = Object.extend({
// as fast as possible. ForAsync also shares some of this, but
// not much.
+ var v;
var i = this.tmpid();
var len = this.tmpid();
var arr = this.tmpid();
@@ -649,7 +649,7 @@ var Compiler = Object.extend({
var key = node.name.children[0];
var val = node.name.children[1];
var k = this.tmpid();
- var v = this.tmpid();
+ v = this.tmpid();
frame.set(key.value, k);
frame.set(val.value, v);
@@ -672,7 +672,7 @@ var Compiler = Object.extend({
}
else {
// Generate a typical array iteration
- var v = this.tmpid();
+ v = this.tmpid();
frame.set(node.name.value, v);
this.emitLine('var ' + len + ' = ' + arr + '.length;');
@@ -953,7 +953,7 @@ var Compiler = Object.extend({
}, this);
},
- compileBlock: function(node, frame) {
+ compileBlock: function(node) {
if(!this.isChild) {
var id = this.tmpid();
@@ -1056,10 +1056,10 @@ var Compiler = Object.extend({
// When compiling the blocks, they should all act as top-level code
this.isChild = false;
- var blocks = node.findAll(nodes.Block);
- for(var i=0; i<blocks.length; i++) {
- var block = blocks[i];
- var name = block.name.value;
+ var i, name, block, blocks = node.findAll(nodes.Block);
+ for (i = 0; i < blocks.length; i++) {
+ block = blocks[i];
+ name = block.name.value;
this.emitFuncBegin('b_' + name);
@@ -1069,9 +1069,9 @@ var Compiler = Object.extend({
}
this.emitLine('return {');
- for(var i=0; i<blocks.length; i++) {
- var block = blocks[i];
- var name = 'b_' + block.name.value;
+ for (i = 0; i < blocks.length; i++) {
+ block = blocks[i];
+ name = 'b_' + block.name.value;
this.emitLine(name + ': ' + name + ',');
}
this.emitLine('root: root\n};');
View
@@ -3,13 +3,13 @@
var path = require('path');
var lib = require('./lib');
var Obj = require('./object');
-var lexer = require('./lexer');
var compiler = require('./compiler');
var builtin_filters = require('./filters');
var builtin_loaders = require('./loaders');
var runtime = require('./runtime');
var globals = require('./globals');
var Frame = runtime.Frame;
+var Template;
var Environment = Obj.extend({
init: function(loaders, opts) {
@@ -19,7 +19,7 @@ var Environment = Obj.extend({
// (the full trace from within nunjucks may confuse developers using
// the library)
// defaults to false
- var opts = this.opts = opts || {};
+ opts = this.opts = opts || {};
this.opts.dev = !!opts.dev;
// The autoescape flag sets global autoescaping. If true,
@@ -331,7 +331,7 @@ var Context = Obj.extend({
}
});
-var Template = Obj.extend({
+Template = Obj.extend({
init: function (src, env, path, eagerCompile) {
this.env = env || new Environment();
@@ -447,6 +447,7 @@ var Template = Obj.extend({
this.path,
this.env.opts);
+ /* jslint evil: true */
var func = new Function(source);
props = func();
}
View
@@ -8,7 +8,7 @@ function normalize(value, defaultValue) {
return defaultValue;
}
return value;
-};
+}
var filters = {
@@ -17,10 +17,11 @@ var filters = {
},
batch: function(arr, linecount, fill_with) {
+ var i;
var res = [];
var tmp = [];
- for(var i=0; i<arr.length; i++) {
+ for(i = 0; i < arr.length; i++) {
if(i % linecount === 0 && tmp.length) {
res.push(tmp);
tmp = [];
@@ -31,7 +32,7 @@ var filters = {
if(tmp.length) {
if(fill_with) {
- for(var i=tmp.length; i<linecount; i++) {
+ for(i = tmp.length; i < linecount; i++) {
tmp.push(fill_with);
}
}
@@ -391,7 +392,7 @@ var filters = {
if (lib.isArray(obj)) {
parts = obj.map(function(item) {
return enc(item[0]) + '=' + enc(item[1]);
- })
+ });
} else {
parts = [];
for (var k in obj) {
View
@@ -62,6 +62,6 @@ var globals = {
joiner: function(sep) {
return joiner(sep);
}
-}
+};
module.exports = globals;
View
@@ -295,8 +295,6 @@ Tokenizer.prototype.nextToken = function() {
Tokenizer.prototype.parseString = function(delimiter) {
this.forward();
- var lineno = this.lineno;
- var colno = this.colno;
var str = '';
while(!this.is_finished() && this.current() !== delimiter) {
View
@@ -23,6 +23,8 @@ exports.withPrettyErrors = function(path, withInternals, func) {
try {
return func();
} catch (e) {
+ // jshint -W022
+ // http://jslinterrors.com/do-not-assign-to-the-exception-parameter
if (!e.Update) {
// not one of ours, cast it
e = new exports.TemplateError(e);
@@ -276,4 +278,4 @@ exports.keys = function(obj) {
}
return keys;
}
-}
+};
View
@@ -2,6 +2,7 @@
var util = require('util');
var lib = require('./lib');
+// jshint -W079
var Object = require('./object');
function traverseAndCheck(obj, type, results) {
@@ -20,7 +21,7 @@ var Node = Object.extend('Node', {
this.colno = colno;
var fields = this.fields;
- for(var i=0, l=fields.length; i<l; i++) {
+ for(var i = 0, l = fields.length; i < l; i++) {
var field = fields[i];
// The first two args are line/col numbers, so offset by 2
@@ -39,17 +40,18 @@ var Node = Object.extend('Node', {
findAll: function(type, results) {
results = results || [];
+ var i, l;
if(this instanceof NodeList) {
var children = this.children;
- for(var i=0, l=children.length; i<l; i++) {
+ for(i = 0, l = children.length; i < l; i++) {
traverseAndCheck(children[i], type, results);
}
}
else {
var fields = this.fields;
- for(var i=0, l=fields.length; i<l; i++) {
+ for(i = 0, l = fields.length; i < l; i++) {
traverseAndCheck(this[fields[i]], type, results);
}
}
@@ -140,14 +142,6 @@ var CompareOperand = Node.extend('CompareOperand', {
fields: ['expr', 'type']
});
-var CustomTag = Node.extend('CustomTag', {
- init: function(lineno, colno, name) {
- this.lineno = lineno;
- this.colno = colno;
- this.name = name;
- }
-});
-
var CallExtension = Node.extend('CallExtension', {
fields: ['extName', 'prop', 'args', 'contentArgs'],
View
@@ -8,6 +8,7 @@ function extend(cls, name, props) {
F.prototype = cls.prototype;
var prototype = new F();
+ // jshint undef: false
var fnTest = /xyz/.test(function(){ xyz; }) ? /\bparent\b/ : /.*/;
props = props || {};
@@ -18,6 +19,7 @@ function extend(cls, name, props) {
if(typeof parent === 'function' &&
typeof src === 'function' &&
fnTest.test(src)) {
+ /*jshint -W083 */
prototype[k] = (function (src, parent) {
return function() {
// Save the current parent method
Oops, something went wrong.

0 comments on commit f6e1641

Please sign in to comment.