JSHint cleanup

This commit is contained in:
Tom MacWright 2011-05-10 17:34:07 -04:00
parent 54f1bb0eed
commit ba332becd3
9 changed files with 48 additions and 41 deletions

View File

@ -10,7 +10,7 @@ var fs = require('fs'),
Step = require('step'); Step = require('step');
// node compatibility for mkdirs below // node compatibility for mkdirs below
var constants = (!process.EEXIST >= 1) ? var constants = ((!process.EEXIST) >= 1) ?
require('constants') : require('constants') :
{ EEXIST: process.EEXIST }; { EEXIST: process.EEXIST };
@ -30,7 +30,7 @@ function External(env, uri) {
this._callbacks = []; this._callbacks = [];
this.done = false; this.done = false;
External.mkdirp(this.env.data_dir, 0755); External.mkdirp(this.env.data_dir, '0755');
if (local) { if (local) {
this.localFile(); this.localFile();
@ -66,8 +66,8 @@ External.prototype.localFile = function() {
External.prototype.downloadFile = function() { External.prototype.downloadFile = function() {
this.tempPath = path.join( this.tempPath = path.join(
this.env.data_dir, this.env.data_dir,
crypto.createHash('md5').update(this.uri).digest('hex') crypto.createHash('md5').update(this.uri).digest('hex') +
+ path.extname(this.uri)); path.extname(this.uri));
fs.stat(this.path(), function(err, stats) { fs.stat(this.path(), function(err, stats) {
if (err) { if (err) {
@ -120,9 +120,9 @@ External.prototype.findDataFile = function(callback) {
}; };
External.prototype.findOneByExtension = function(ext, callback) { External.prototype.findOneByExtension = function(ext, callback) {
var cb = function(err, files) { callback(null, files.pop()); } var cb = function(err, files) { callback(null, files.pop()); };
this.findByExtension(ext, cb); this.findByExtension(ext, cb);
} };
// Find a file by extension in `this.path()`. // Find a file by extension in `this.path()`.
// Ignores .directories and .files // Ignores .directories and .files
@ -137,7 +137,6 @@ External.prototype.findByExtension = function(ext, callback) {
running = 0; running = 0;
callback(err); callback(err);
return; return;
i;
} }
files.forEach(function(file) { files.forEach(function(file) {
// Ignore dotfiles and dot-directories // Ignore dotfiles and dot-directories
@ -186,42 +185,42 @@ External.mkdirp = function mkdirP(p, mode, f) {
External.types = [ External.types = [
{ {
extension: /\.zip/, extension: /\.zip/,
datafile: function(d, c) { d.findOneByExtension('.shp', c) }, datafile: function(d, c) { d.findOneByExtension('.shp', c); },
ds_options: { ds_options: {
type: 'shape' type: 'shape'
} }
}, },
{ {
extension: /\.shp/, extension: /\.shp/,
datafile: function(d, c) { c(null, d.path()) }, datafile: function(d, c) { c(null, d.path()); },
ds_options: { ds_options: {
type: 'shape' type: 'shape'
} }
}, },
{ {
extension: /\.png/, extension: /\.png/,
datafile: function(d, c) { c(null, d.path()) }, datafile: function(d, c) { c(null, d.path()); }
}, },
{ {
extension: /\.jpe?g/, extension: /\.jpe?g/
}, },
{ {
extension: /\.geotiff?|\.tiff?/, extension: /\.geotiff?|\.tiff?/,
datafile: function(d, c) { c(null, d.path()) }, datafile: function(d, c) { c(null, d.path()); },
ds_options: { ds_options: {
type: 'gdal' type: 'gdal'
} }
}, },
{ {
extension: /\.vrt/, extension: /\.vrt/,
datafile: function(d, c) { c(null, d.path()) }, datafile: function(d, c) { c(null, d.path()); },
ds_options: { ds_options: {
type: 'gdal' type: 'gdal'
} }
}, },
{ {
extension: /\.kml/, extension: /\.kml/,
datafile: function(d, c) { c(null, d.path()) }, datafile: function(d, c) { c(null, d.path()); },
ds_options: { ds_options: {
type: 'ogr', type: 'ogr',
layer_by_index: 0 layer_by_index: 0
@ -229,7 +228,7 @@ External.types = [
}, },
{ {
extension: /\.geojson|\.json/, extension: /\.geojson|\.json/,
datafile: function(d, c) { c(null, d.path()) }, datafile: function(d, c) { c(null, d.path()); },
ds_options: { ds_options: {
type: 'ogr', type: 'ogr',
layer_by_index: 0 layer_by_index: 0
@ -237,7 +236,7 @@ External.types = [
}, },
{ {
extension: /\.rss/, extension: /\.rss/,
datafile: function(d, c) { c(d.path()) }, datafile: function(d, c) { c(d.path()); },
ds_options: { ds_options: {
type: 'ogr', type: 'ogr',
layer_by_index: 0 layer_by_index: 0
@ -245,7 +244,7 @@ External.types = [
}, },
{ {
extension: /.*/g, extension: /.*/g,
datafile: function(d, c) { c(d.path()) }, datafile: function(d, c) { c(d.path()); }
} }
]; ];
@ -290,7 +289,7 @@ External.processors['.zip'] = function(tempPath, destPath, callback) {
zf.names.forEach(function(name) { zf.names.forEach(function(name) {
var next = group(); var next = group();
var uncompressed = path.join(destPath, name); var uncompressed = path.join(destPath, name);
External.mkdirp(path.dirname(uncompressed), 0755, function(err) { External.mkdirp(path.dirname(uncompressed), '0755', function(err) {
if (err && err.errno != constants.EEXIST) { if (err && err.errno != constants.EEXIST) {
callback("Couldn't create directory " + path.dirname(name)); callback("Couldn't create directory " + path.dirname(name));
} }
@ -300,7 +299,7 @@ External.processors['.zip'] = function(tempPath, destPath, callback) {
next(); next();
} else { } else {
var buffer = zf.readFile(name, function(err, buffer) { var buffer = zf.readFile(name, function(err, buffer) {
fd = fs.open(uncompressed, 'w', 0755, function(err, fd) { fd = fs.open(uncompressed, 'w', '0755', function(err, fd) {
sys.debug('saving to: ' + uncompressed); sys.debug('saving to: ' + uncompressed);
fs.write(fd, buffer, 0, buffer.length, null, fs.write(fd, buffer, 0, buffer.length, null,
function(err, written) { function(err, written) {

View File

@ -5,7 +5,7 @@ tree.functions = {
return this.rgba(r, g, b, 1.0); return this.rgba(r, g, b, 1.0);
}, },
rgba: function (r, g, b, a) { rgba: function (r, g, b, a) {
var rgb = [r, g, b].map(function (c) { return number(c) }), var rgb = [r, g, b].map(function (c) { return number(c); }),
a = number(a); a = number(a);
return new tree.Color(rgb, a); return new tree.Color(rgb, a);
}, },

View File

@ -18,7 +18,7 @@ var carto = {
options = options || {}; options = options || {};
if (options.silent) { return } if (options.silent) { return; }
options.indent = options.indent || ''; options.indent = options.indent || '';
@ -33,9 +33,9 @@ var carto = {
if (extract[1] === '' && typeof extract[2] === 'undefined') { if (extract[1] === '' && typeof extract[2] === 'undefined') {
extract[1] = '¶'; extract[1] = '¶';
} }
error.push(ctx.line + ' ' + extract[1].slice(0, ctx.column) error.push(ctx.line + ' ' + extract[1].slice(0, ctx.column) +
+ stylize(stylize(extract[1][ctx.column], 'bold') stylize(stylize(extract[1][ctx.column], 'bold') +
+ extract[1].slice(ctx.column + 1), 'yellow')); extract[1].slice(ctx.column + 1), 'yellow'));
if (typeof(extract[2]) === 'string') { if (typeof(extract[2]) === 'string') {
error.push(stylize((ctx.line + 1) + ' ' + extract[2], 'grey')); error.push(stylize((ctx.line + 1) + ' ' + extract[2], 'grey'));
@ -51,7 +51,7 @@ var carto = {
sys.error(stylize('from ', 'red') + (ctx.filename || '')); sys.error(stylize('from ', 'red') + (ctx.filename || ''));
sys.error(stylize(ctx.callLine, 'grey') + ' ' + ctx.callExtract); sys.error(stylize(ctx.callLine, 'grey') + ' ' + ctx.callExtract);
} }
if (ctx.stack) { sys.error(stylize(ctx.stack, 'red')) } if (ctx.stack) { sys.error(stylize(ctx.stack, 'red')); }
} }
}; };
@ -99,7 +99,7 @@ carto.Parser.importer = function(file, paths, callback) {
require('carto/functions'); require('carto/functions');
for (var k in carto) { exports[k] = carto[k] } for (var k in carto) { exports[k] = carto[k]; }
// Stylize a string // Stylize a string
function stylize(str, style) { function stylize(str, style) {

View File

@ -1,11 +1,11 @@
var carto, tree; var carto, tree;
if (typeof(process) !== 'undefined') { if (typeof(process) !== 'undefined') {
carto = exports, carto = exports;
tree = require('carto/tree'); tree = require('carto/tree');
} else { } else {
if (typeof(window.carto) === 'undefined') { window.carto = {} } if (typeof(window.carto) === 'undefined') { window.carto = {}; }
carto = window.carto, carto = window.carto;
tree = window.carto.tree = {}; tree = window.carto.tree = {};
} }
// //
@ -76,13 +76,21 @@ carto.Parser = function Parser(env) {
callback(root); callback(root);
if (that.queue.length === 0) { finish() } // Call `finish` if we're done importing if (that.queue.length === 0) { finish(); } // Call `finish` if we're done importing
}, env); }, env);
} }
}; };
function save() { temp = chunks[j], memo = i, current = i } function save() {
function restore() { chunks[j] = temp, i = memo, current = i } temp = chunks[j];
memo = i;
current = i;
}
function restore() {
chunks[j] = temp;
i = memo;
current = i;
}
function sync() { function sync() {
if (i > current) { if (i > current) {
@ -132,13 +140,13 @@ carto.Parser = function Parser(env) {
while (i < endIndex) { while (i < endIndex) {
c = input.charCodeAt(i); c = input.charCodeAt(i);
if (! (c === 32 || c === 10 || c === 9)) { break } if (! (c === 32 || c === 10 || c === 9)) { break; }
i++; i++;
} }
chunks[j] = chunks[j].slice(length + (i - mem)); chunks[j] = chunks[j].slice(length + (i - mem));
current = i; current = i;
if (chunks[j].length === 0 && j < chunks.length - 1) { j++ } if (chunks[j].length === 0 && j < chunks.length - 1) { j++; }
if (typeof(match) === 'string') { if (typeof(match) === 'string') {
return match; return match;
@ -167,7 +175,7 @@ carto.Parser = function Parser(env) {
lines = input.split('\n'); lines = input.split('\n');
line = (input.slice(0, i).match(/\n/g) || '').length + 1; line = (input.slice(0, i).match(/\n/g) || '').length + 1;
for (var n = i, column = -1; n >= 0 && input.charAt(n) !== '\n'; n--) { column++ } for (var n = i, column = -1; n >= 0 && input.charAt(n) !== '\n'; n--) { column++; }
return { return {
name: 'ParseError', name: 'ParseError',

View File

@ -8,7 +8,7 @@ tree.Alpha.prototype = {
return 'alpha(opacity=' + return 'alpha(opacity=' +
(this.value.toString ? this.value.toString() : this.value) + ')'; (this.value.toString ? this.value.toString() : this.value) + ')';
}, },
eval: function() { return this } eval: function() { return this; }
}; };
})(require('carto/tree')); })(require('carto/tree'));

View File

@ -7,7 +7,7 @@ tree.Anonymous.prototype = {
toString: function() { toString: function() {
return this.value; return this.value;
}, },
eval: function() { return this } eval: function() { return this; }
}; };
})(require('carto/tree')); })(require('carto/tree'));

View File

@ -21,7 +21,7 @@ tree.Call.prototype = {
// The function should receive the value, not the variable. // The function should receive the value, not the variable.
// //
eval: function(env) { eval: function(env) {
var args = this.args.map(function(a) { return a.eval(env) }); var args = this.args.map(function(a) { return a.eval(env); });
for (var i = 0; i < args.length; i++) { for (var i = 0; i < args.length; i++) {
if (args[i].is === 'undefined') { if (args[i].is === 'undefined') {
@ -36,7 +36,7 @@ tree.Call.prototype = {
return tree.functions[this.name].apply(tree.functions, args); return tree.functions[this.name].apply(tree.functions, args);
} else { // 2. } else { // 2.
return new tree.Anonymous(this.name + return new tree.Anonymous(this.name +
'(' + args.map(function(a) { return a.toString() }).join(', ') + ')'); '(' + args.map(function(a) { return a.toString(); }).join(', ') + ')');
} }
}, },

View File

@ -24,7 +24,7 @@ tree.Color = function Color(rgb, a) {
this.alpha = typeof(a) === 'number' ? a : 1; this.alpha = typeof(a) === 'number' ? a : 1;
}; };
tree.Color.prototype = { tree.Color.prototype = {
eval: function() { return this }, eval: function() { return this; },
// //
// If we have some transparency, the only way to represent it // If we have some transparency, the only way to represent it

View File

@ -8,7 +8,7 @@ tree.Comment.prototype = {
toString: function(env) { toString: function(env) {
return '<!--' + this.value + '-->'; return '<!--' + this.value + '-->';
}, },
eval: function() { return this } eval: function() { return this; }
}; };
})(require('carto/tree')); })(require('carto/tree'));