Style updates

This commit is contained in:
kpdecker
2015-08-03 16:43:09 -05:00
parent 8e868ab225
commit 9b1f9c7e44
29 changed files with 154 additions and 124 deletions
+2
View File
@@ -9,6 +9,8 @@ module.exports = function(grunt) {
},
files: [
'*.js',
'bench/**/*.js',
'tasks/**/*.js',
'lib/**/!(*.min|parser).js',
'spec/**/!(*.amd|json2|require).js'
]
+14
View File
@@ -0,0 +1,14 @@
{
"globals": {
"require": true
},
"rules": {
// Disabling for tests, for now.
"no-path-concat": 0,
"no-var": 0,
"no-shadow": 0,
"handle-callback-err": 0,
"no-console": 0
}
}
+1 -2
View File
@@ -1,5 +1,4 @@
var _ = require('underscore'),
async = require('async'),
var async = require('async'),
fs = require('fs'),
zlib = require('zlib');
+1 -1
View File
@@ -2,7 +2,7 @@ var fs = require('fs');
var metrics = fs.readdirSync(__dirname);
metrics.forEach(function(metric) {
if (metric === 'index.js' || !/(.*)\.js$/.test(metric)) {
if (metric === 'index.js' || !(/(.*)\.js$/.test(metric))) {
return;
}
+1 -1
View File
@@ -1,6 +1,6 @@
module.exports = {
helpers: {
foo: function(options) {
foo: function() {
return '';
}
},
+5 -5
View File
@@ -1,7 +1,7 @@
module.exports = {
context: { names: [{name: "Moe"}, {name: "Larry"}, {name: "Curly"}, {name: "Shemp"}] },
handlebars: "{{#each names}}{{name}}{{/each}}",
dust: "{#names}{name}{/names}",
mustache: "{{#names}}{{name}}{{/names}}",
eco: "<% for item in @names: %><%= item.name %><% end %>"
context: { names: [{name: 'Moe'}, {name: 'Larry'}, {name: 'Curly'}, {name: 'Shemp'}] },
handlebars: '{{#each names}}{{name}}{{/each}}',
dust: '{#names}{name}{/names}',
mustache: '{{#names}}{{name}}{{/names}}',
eco: '<% for item in @names: %><%= item.name %><% end %>'
};
+3 -3
View File
@@ -1,4 +1,4 @@
module.exports = {
context: { names: [{name: "Moe"}, {name: "Larry"}, {name: "Curly"}, {name: "Shemp"}] },
handlebars: "{{#names}}{{name}}{{/names}}"
}
context: { names: [{name: 'Moe'}, {name: 'Larry'}, {name: 'Curly'}, {name: 'Shemp'}] },
handlebars: '{{#names}}{{name}}{{/names}}'
};
+4 -4
View File
@@ -3,13 +3,13 @@ var fs = require('fs');
module.exports = {
context: {
header: function() {
return "Colors";
return 'Colors';
},
hasItems: true, // To make things fairer in mustache land due to no `{{if}}` construct on arrays
items: [
{name: "red", current: true, url: "#Red"},
{name: "green", current: false, url: "#Green"},
{name: "blue", current: false, url: "#Blue"}
{name: 'red', current: true, url: '#Red'},
{name: 'green', current: false, url: '#Green'},
{name: 'blue', current: false, url: '#Blue'}
]
},
+3 -3
View File
@@ -1,4 +1,4 @@
module.exports = {
context: { names: [{name: "Moe"}, {name: "Larry"}, {name: "Curly"}, {name: "Shemp"}] },
handlebars: "{{#each names}}{{@index}}{{name}}{{/each}}"
}
context: { names: [{name: 'Moe'}, {name: 'Larry'}, {name: 'Curly'}, {name: 'Shemp'}] },
handlebars: '{{#each names}}{{@index}}{{name}}{{/each}}'
};
+4 -4
View File
@@ -1,6 +1,6 @@
module.exports = {
context: { names: [{name: "Moe"}, {name: "Larry"}, {name: "Curly"}, {name: "Shemp"}], foo: 'bar' },
handlebars: "{{#each names}}{{../foo}}{{/each}}",
mustache: "{{#names}}{{foo}}{{/names}}",
eco: "<% for item in @names: %><%= @foo %><% end %>"
context: { names: [{name: 'Moe'}, {name: 'Larry'}, {name: 'Curly'}, {name: 'Shemp'}], foo: 'bar' },
handlebars: '{{#each names}}{{../foo}}{{/each}}',
mustache: '{{#names}}{{foo}}{{/names}}',
eco: '<% for item in @names: %><%= @foo %><% end %>'
};
+4 -4
View File
@@ -1,6 +1,6 @@
module.exports = {
context: { names: [{bat: 'foo', name: ["Moe"]}, {bat: 'foo', name: ["Larry"]}, {bat: 'foo', name: ["Curly"]}, {bat: 'foo', name: ["Shemp"]}], foo: 'bar' },
handlebars: "{{#each names}}{{#each name}}{{../bat}}{{../../foo}}{{/each}}{{/each}}",
mustache: "{{#names}}{{#name}}{{bat}}{{foo}}{{/name}}{{/names}}",
eco: "<% for item in @names: %><% for child in item.name: %><%= item.bat %><%= @foo %><% end %><% end %>"
context: { names: [{bat: 'foo', name: ['Moe']}, {bat: 'foo', name: ['Larry']}, {bat: 'foo', name: ['Curly']}, {bat: 'foo', name: ['Shemp']}], foo: 'bar' },
handlebars: '{{#each names}}{{#each name}}{{../bat}}{{../../foo}}{{/each}}{{/each}}',
mustache: '{{#names}}{{#name}}{{bat}}{{foo}}{{/name}}{{/names}}',
eco: '<% for item in @names: %><% for child in item.name: %><%= item.bat %><%= @foo %><% end %><% end %>'
};
+1 -1
View File
@@ -2,7 +2,7 @@ var fs = require('fs');
var templates = fs.readdirSync(__dirname);
templates.forEach(function(template) {
if (template === 'index.js' || !/(.*)\.js$/.test(template)) {
if (template === 'index.js' || !(/(.*)\.js$/.test(template))) {
return;
}
module.exports[RegExp.$1] = require('./' + RegExp.$1);
+2 -2
View File
@@ -1,4 +1,4 @@
module.exports = {
context: { person: { name: "Larry", age: 45 } },
handlebars: "{{#person}}{{name}}{{age}}{{/person}}"
context: { person: { name: 'Larry', age: 45 } },
handlebars: '{{#person}}{{name}}{{age}}{{/person}}'
};
+5 -5
View File
@@ -1,7 +1,7 @@
module.exports = {
context: { person: { name: "Larry", age: 45 } },
handlebars: "{{#with person}}{{name}}{{age}}{{/with}}",
dust: "{#person}{name}{age}{/person}",
eco: "<%= @person.name %><%= @person.age %>",
mustache: "{{#person}}{{name}}{{age}}{{/person}}"
context: { person: { name: 'Larry', age: 45 } },
handlebars: '{{#with person}}{{name}}{{age}}{{/with}}',
dust: '{#person}{name}{age}{/person}',
eco: '<%= @person.name %><%= @person.age %>',
mustache: '{{#person}}{{name}}{{age}}{{/person}}'
};
+5 -5
View File
@@ -1,10 +1,10 @@
module.exports = {
context: { name: '1', kids: [{ name: '1.1', kids: [{name: '1.1.1', kids: []}] }] },
partials: {
mustache: { recursion: "{{name}}{{#kids}}{{>recursion}}{{/kids}}" },
handlebars: { recursion: "{{name}}{{#each kids}}{{>recursion}}{{/each}}" }
mustache: { recursion: '{{name}}{{#kids}}{{>recursion}}{{/kids}}' },
handlebars: { recursion: '{{name}}{{#each kids}}{{>recursion}}{{/each}}' }
},
handlebars: "{{name}}{{#each kids}}{{>recursion}}{{/each}}",
dust: "{name}{#kids}{>recursion:./}{/kids}",
mustache: "{{name}}{{#kids}}{{>recursion}}{{/kids}}"
handlebars: '{{name}}{{#each kids}}{{>recursion}}{{/each}}',
dust: '{name}{#kids}{>recursion:./}{/kids}',
mustache: '{{name}}{{#kids}}{{>recursion}}{{/kids}}'
};
+6 -6
View File
@@ -1,11 +1,11 @@
module.exports = {
context: { peeps: [{name: "Moe", count: 15}, {name: "Larry", count: 5}, {name: "Curly", count: 1}] },
context: { peeps: [{name: 'Moe', count: 15}, {name: 'Larry', count: 5}, {name: 'Curly', count: 1}] },
partials: {
mustache: { variables: "Hello {{name}}! You have {{count}} new messages." },
handlebars: { variables: "Hello {{name}}! You have {{count}} new messages." }
mustache: { variables: 'Hello {{name}}! You have {{count}} new messages.' },
handlebars: { variables: 'Hello {{name}}! You have {{count}} new messages.' }
},
handlebars: "{{#each peeps}}{{>variables}}{{/each}}",
dust: "{#peeps}{>variables/}{/peeps}",
mustache: "{{#peeps}}{{>variables}}{{/peeps}}"
handlebars: '{{#each peeps}}{{>variables}}{{/each}}',
dust: '{#peeps}{>variables/}{/peeps}',
mustache: '{{#peeps}}{{>variables}}{{/peeps}}'
};
+5 -5
View File
@@ -1,7 +1,7 @@
module.exports = {
context: { person: { name: {bar: {baz: "Larry"}}, age: 45 } },
handlebars: "{{person.name.bar.baz}}{{person.age}}{{person.foo}}{{animal.age}}",
dust: "{person.name.bar.baz}{person.age}{person.foo}{animal.age}",
eco: "<%= @person.name.bar.baz %><%= @person.age %><%= @person.foo %><% if @animal: %><%= @animal.age %><% end %>",
mustache: "{{person.name.bar.baz}}{{person.age}}{{person.foo}}{{animal.age}}"
context: { person: { name: {bar: {baz: 'Larry'}}, age: 45 } },
handlebars: '{{person.name.bar.baz}}{{person.age}}{{person.foo}}{{animal.age}}',
dust: '{person.name.bar.baz}{person.age}{person.foo}{animal.age}',
eco: '<%= @person.name.bar.baz %><%= @person.age %><%= @person.foo %><% if @animal: %><%= @animal.age %><% end %>',
mustache: '{{person.name.bar.baz}}{{person.age}}{{person.foo}}{{animal.age}}'
};
+4 -4
View File
@@ -1,7 +1,7 @@
module.exports = {
context: {},
handlebars: "Hello world",
dust: "Hello world",
mustache: "Hello world",
eco: "Hello world"
handlebars: 'Hello world',
dust: 'Hello world',
mustache: 'Hello world',
eco: 'Hello world'
};
+3 -3
View File
@@ -4,11 +4,11 @@ module.exports = {
return 'foo ' + value;
},
header: function() {
return "Colors";
return 'Colors';
}
},
handlebars: "{{echo (header)}}",
eco: "<%= @echo(@header()) %>"
handlebars: '{{echo (header)}}',
eco: '<%= @echo(@header()) %>'
};
module.exports.context = module.exports.helpers;
+5 -5
View File
@@ -1,8 +1,8 @@
module.exports = {
context: {name: "Mick", count: 30},
handlebars: "Hello {{name}}! You have {{count}} new messages.",
dust: "Hello {name}! You have {count} new messages.",
mustache: "Hello {{name}}! You have {{count}} new messages.",
eco: "Hello <%= @name %>! You have <%= @count %> new messages."
context: {name: 'Mick', count: 30},
handlebars: 'Hello {{name}}! You have {{count}} new messages.',
dust: 'Hello {name}! You have {count} new messages.',
mustache: 'Hello {{name}}! You have {{count}} new messages.',
eco: 'Hello <%= @name %>! You have <%= @count %> new messages.'
};
+14 -15
View File
@@ -1,23 +1,22 @@
var _ = require('underscore'),
runner = require('./util/template-runner'),
templates = require('./templates'),
eco, dust, Handlebars, Mustache, eco;
try {
dust = require("dustjs-linkedin");
dust = require('dustjs-linkedin');
} catch (err) { /* NOP */ }
try {
Mustache = require("mustache");
Mustache = require('mustache');
} catch (err) { /* NOP */ }
try {
eco = require("eco");
eco = require('eco');
} catch (err) { /* NOP */ }
function error() {
throw new Error("EWOT");
throw new Error('EWOT');
}
function makeSuite(bench, name, template, handlebarsOnly) {
@@ -34,19 +33,19 @@ function makeSuite(bench, name, template, handlebarsOnly) {
mustacheOut;
var handlebar = Handlebars.compile(template.handlebars, {data: false}),
compat = Handlebars.compile(template.handlebars, {data: false, compat: true}),
compat = Handlebars.compile(template.handlebars, {data: false, compat: true}),
options = {helpers: template.helpers};
_.each(template.partials && template.partials.handlebars, function(partial, name) {
_.each(template.partials && template.partials.handlebars, function(partial) {
Handlebars.registerPartial(name, Handlebars.compile(partial, {data: false}));
});
handlebarsOut = handlebar(context, options);
bench("handlebars", function() {
bench('handlebars', function() {
handlebar(context, options);
});
compatOut = compat(context, options);
bench("compat", function() {
bench('compat', function() {
compat(context, options);
});
@@ -61,8 +60,8 @@ function makeSuite(bench, name, template, handlebarsOnly) {
dust.render(templateName, context, function(err, out) { dustOut = out; });
bench("dust", function() {
dust.render(templateName, context, function(err, out) { });
bench('dust', function() {
dust.render(templateName, context, function() {});
});
} else {
bench('dust', error);
@@ -75,11 +74,11 @@ function makeSuite(bench, name, template, handlebarsOnly) {
ecoOut = ecoTemplate(context);
bench("eco", function() {
bench('eco', function() {
ecoTemplate(context);
});
} else {
bench("eco", error);
bench('eco', error);
}
}
@@ -90,11 +89,11 @@ function makeSuite(bench, name, template, handlebarsOnly) {
if (mustacheSource) {
mustacheOut = Mustache.to_html(mustacheSource, context, mustachePartials);
bench("mustache", function() {
bench('mustache', function() {
Mustache.to_html(mustacheSource, context, mustachePartials);
});
} else {
bench("mustache", error);
bench('mustache', error);
}
}
+33 -35
View File
@@ -1,7 +1,7 @@
var _ = require('underscore'),
Benchmark = require("benchmark");
Benchmark = require('benchmark');
var BenchWarmer = function(names) {
function BenchWarmer() {
this.benchmarks = [];
this.currentBenches = [];
this.names = [];
@@ -9,9 +9,9 @@ var BenchWarmer = function(names) {
this.minimum = Infinity;
this.maximum = -Infinity;
this.errors = {};
};
}
var print = require("sys").print;
var print = require('sys').print;
BenchWarmer.prototype = {
winners: function(benches) {
@@ -29,7 +29,7 @@ BenchWarmer.prototype = {
});
},
push: function(name, fn) {
if(this.names.indexOf(name) == -1) {
if (this.names.indexOf(name) == -1) {
this.names.push(name);
}
@@ -37,9 +37,9 @@ BenchWarmer.prototype = {
this.first = false;
var bench = new Benchmark(fn, {
name: this.suiteName + ": " + name,
name: this.suiteName + ': ' + name,
onComplete: function() {
if(first) { self.startLine(suiteName); }
if (first) { self.startLine(suiteName); }
self.writeBench(bench);
self.currentBenches.push(bench);
}, onError: function() {
@@ -58,7 +58,7 @@ BenchWarmer.prototype = {
this.printHeader('ops/msec', true);
Benchmark.invoke(this.benchmarks, {
name: "run",
name: 'run',
onComplete: function() {
self.scaleTimes();
@@ -76,7 +76,7 @@ BenchWarmer.prototype = {
print('\n');
var errors = false, prop, bench;
for(prop in self.errors) {
for (prop in self.errors) {
if (self.errors.hasOwnProperty(prop)
&& self.errors[prop].error.message !== 'EWOT') {
errors = true;
@@ -84,18 +84,18 @@ BenchWarmer.prototype = {
}
}
if(errors) {
print("\n\nErrors:\n");
for(prop in self.errors) {
if (errors) {
print('\n\nErrors:\n');
for (prop in self.errors) {
if (self.errors.hasOwnProperty(prop)
&& self.errors[prop].error.message !== 'EWOT') {
bench = self.errors[prop];
print("\n" + bench.name + ":\n");
print('\n' + bench.name + ':\n');
print(bench.error.message);
if(bench.error.stack) {
print(bench.error.stack.join("\n"));
if (bench.error.stack) {
print(bench.error.stack.join('\n'));
}
print("\n");
print('\n');
}
}
}
@@ -104,7 +104,7 @@ BenchWarmer.prototype = {
}
});
print("\n");
print('\n');
},
scaleTimes: function() {
@@ -121,10 +121,10 @@ BenchWarmer.prototype = {
printHeader: function(title, winners) {
var benchSize = 0, names = this.names, i, l;
for(i=0, l=names.length; i<l; i++) {
for (i = 0, l = names.length; i < l; i++) {
var name = names[i];
if(benchSize < name.length) { benchSize = name.length; }
if (benchSize < name.length) { benchSize = name.length; }
}
this.nameSize = benchSize + 2;
@@ -133,28 +133,28 @@ BenchWarmer.prototype = {
this.startLine(title);
horSize = horSize + this.benchSize;
for(i=0, l=names.length; i<l; i++) {
for (i = 0, l = names.length; i < l; i++) {
this.writeValue(names[i]);
horSize = horSize + this.benchSize;
}
if (winners) {
print("WINNER(S)");
horSize = horSize + "WINNER(S)".length;
print('WINNER(S)');
horSize = horSize + 'WINNER(S)'.length;
}
print("\n" + new Array(horSize + 1).join("-"));
print('\n' + new Array(horSize + 1).join('-'));
},
startLine: function(name) {
var winners = Benchmark.map(this.winners(this.currentBenches), function(bench) {
return bench.name.split(": ")[1];
return bench.name.split(': ')[1];
});
this.currentBenches = [];
print(winners.join(", "));
print("\n");
print(winners.join(', '));
print('\n');
if (name) {
this.writeValue(name);
@@ -163,9 +163,9 @@ BenchWarmer.prototype = {
writeBench: function(bench) {
var out;
if(!bench.error) {
if (!bench.error) {
var count = bench.hz,
moe = count * bench.stats.rme / 100,
moe = count * bench.stats.rme / 100,
minimum,
maximum;
@@ -174,24 +174,22 @@ BenchWarmer.prototype = {
minimum = count - moe;
maximum = count + moe;
out = count + " ±" + moe + " (" + bench.cycles + ")";
out = count + ' ±' + moe + ' (' + bench.cycles + ')';
this.times[bench.suiteName][bench.benchName] = count;
this.minimum = Math.min(this.minimum, minimum);
this.maximum = Math.max(this.maximum, maximum);
} else if (bench.error.message === 'EWOT') {
out = 'NA';
} else {
if (bench.error.message === 'EWOT') {
out = 'NA';
} else {
out = 'E';
}
out = 'E';
}
this.writeValue(out);
},
writeValue: function(out) {
var padding = this.benchSize - out.length + 1;
out = out + new Array(padding).join(" ");
out = out + new Array(padding).join(' ');
print(out);
}
};
+3 -1
View File
@@ -22,6 +22,8 @@ module.exports = function(grunt, makeSuite, callback) {
});
warmer.bench(function() {
callback && callback(warmer.times, warmer.scaled);
if (callback) {
callback(warmer.times, warmer.scaled);
}
});
};
+16
View File
@@ -0,0 +1,16 @@
{
"globals": {
"require": true
},
"rules": {
// Disabling for tests, for now.
"no-path-concat": 0,
"no-var": 0,
"no-shadow": 0,
"handle-callback-err": 0,
"no-console": 0,
"no-process-env": 0,
"dot-notation": [2, {"allowKeywords": true}]
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ module.exports = function(grunt) {
return done();
}
emit(keen, events, function(err, res) {
emit(keen, events, function(err) {
if (err) {
throw err;
}
+1 -1
View File
@@ -6,7 +6,7 @@ module.exports = function(grunt) {
var cmd = './node_modules/.bin/jison';
if(process.platform === 'win32'){
if (process.platform === 'win32') {
cmd = 'node_modules\\.bin\\jison.cmd';
}
+1 -1
View File
@@ -60,7 +60,7 @@ module.exports = function(grunt) {
async.forEach(_.keys(files), function(file, callback) {
var params = {Bucket: bucket, Key: file, Body: grunt.file.read(files[file])};
s3.putObject(params, function(err, data) {
s3.putObject(params, function(err) {
if (err) {
throw err;
} else {
+5 -5
View File
@@ -50,7 +50,7 @@ module.exports = {
childProcess.exec('git rev-parse --short origin/master', {}, function(err, stdout) {
// This will error if master was not checked out but in this case we know we are not master
// so we can ignore.
if (err && !/Needed a single revision/.test(err.message)) {
if (err && !(/Needed a single revision/.test(err.message))) {
throw new Error('git.master: ' + err.message);
}
@@ -59,7 +59,7 @@ module.exports = {
},
add: function(path, callback) {
childProcess.exec('git add -f ' + path, {}, function(err, stdout) {
childProcess.exec('git add -f ' + path, {}, function(err) {
if (err) {
throw new Error('git.add: ' + err.message);
}
@@ -68,7 +68,7 @@ module.exports = {
});
},
commit: function(name, callback) {
childProcess.exec('git commit --message=' + name, {}, function(err, stdout) {
childProcess.exec('git commit --message=' + name, {}, function(err) {
if (err) {
throw new Error('git.commit: ' + err.message);
}
@@ -77,7 +77,7 @@ module.exports = {
});
},
tag: function(name, callback) {
childProcess.exec('git tag -a --message=' + name + ' ' + name, {}, function(err, stdout, stderr) {
childProcess.exec('git tag -a --message=' + name + ' ' + name, {}, function(err) {
if (err) {
throw new Error('git.tag: ' + err.message);
}
@@ -98,7 +98,7 @@ module.exports = {
});
var versionTags = tags.filter(function(info) {
return /^v/.test(info[0]);
return (/^v/.test(info[0]));
});
callback(undefined, versionTags[0] || tags[0]);
+2 -2
View File
@@ -33,9 +33,9 @@ module.exports = function(grunt) {
});
});
function replace(path, regex, replace) {
function replace(path, regex, value) {
var content = grunt.file.read(path);
content = content.replace(regex, replace);
content = content.replace(regex, value);
grunt.file.write(path, content);
}
};