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

View File

@ -5,7 +5,7 @@ tree.functions = {
return this.rgba(r, g, b, 1.0);
},
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);
return new tree.Color(rgb, a);
},

View File

@ -18,7 +18,7 @@ var carto = {
options = options || {};
if (options.silent) { return }
if (options.silent) { return; }
options.indent = options.indent || '';
@ -33,9 +33,9 @@ var carto = {
if (extract[1] === '' && typeof extract[2] === 'undefined') {
extract[1] = '¶';
}
error.push(ctx.line + ' ' + extract[1].slice(0, ctx.column)
+ stylize(stylize(extract[1][ctx.column], 'bold')
+ extract[1].slice(ctx.column + 1), 'yellow'));
error.push(ctx.line + ' ' + extract[1].slice(0, ctx.column) +
stylize(stylize(extract[1][ctx.column], 'bold') +
extract[1].slice(ctx.column + 1), 'yellow'));
if (typeof(extract[2]) === 'string') {
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(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');
for (var k in carto) { exports[k] = carto[k] }
for (var k in carto) { exports[k] = carto[k]; }
// Stylize a string
function stylize(str, style) {

View File

@ -1,11 +1,11 @@
var carto, tree;
if (typeof(process) !== 'undefined') {
carto = exports,
carto = exports;
tree = require('carto/tree');
} else {
if (typeof(window.carto) === 'undefined') { window.carto = {} }
carto = window.carto,
if (typeof(window.carto) === 'undefined') { window.carto = {}; }
carto = window.carto;
tree = window.carto.tree = {};
}
//
@ -76,13 +76,21 @@ carto.Parser = function Parser(env) {
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);
}
};
function save() { temp = chunks[j], memo = i, current = i }
function restore() { chunks[j] = temp, i = memo, current = i }
function save() {
temp = chunks[j];
memo = i;
current = i;
}
function restore() {
chunks[j] = temp;
i = memo;
current = i;
}
function sync() {
if (i > current) {
@ -132,13 +140,13 @@ carto.Parser = function Parser(env) {
while (i < endIndex) {
c = input.charCodeAt(i);
if (! (c === 32 || c === 10 || c === 9)) { break }
if (! (c === 32 || c === 10 || c === 9)) { break; }
i++;
}
chunks[j] = chunks[j].slice(length + (i - mem));
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') {
return match;
@ -167,7 +175,7 @@ carto.Parser = function Parser(env) {
lines = input.split('\n');
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 {
name: 'ParseError',

View File

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

View File

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

View File

@ -21,7 +21,7 @@ tree.Call.prototype = {
// The function should receive the value, not the variable.
//
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++) {
if (args[i].is === 'undefined') {
@ -36,7 +36,7 @@ tree.Call.prototype = {
return tree.functions[this.name].apply(tree.functions, args);
} else { // 2.
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;
};
tree.Color.prototype = {
eval: function() { return this },
eval: function() { return this; },
//
// If we have some transparency, the only way to represent it

View File

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