From e4da13189d7b2220806885898b528ab7ed5953e3 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Sun, 15 Mar 2015 23:37:03 +0100 Subject: [PATCH 01/17] Adds jshint - dependency - makefile target - relax some rules Work in progress --- .jshintrc | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 4 +++ package.json | 1 + 3 files changed, 97 insertions(+) create mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..767df861 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,92 @@ +{ +// // JSHint Default Configuration File (as on JSHint website) +// // See http://jshint.com/docs/ for more details +// +// "maxerr" : 50, // {int} Maximum error before stopping +// +// // Enforcing +// "bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.) +// "camelcase" : false, // true: Identifiers must be in camelCase +// "curly" : true, // true: Require {} for every new block or scope + "eqeqeq" : true, // true: Require triple equals (===) for comparison + "forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty() + "freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc. + "immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());` +// "indent" : 4, // {int} Number of spaces to use for indentation +// "latedef" : false, // true: Require variables/functions to be defined before being used +// "newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()` + "noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee` +// "noempty" : true, // true: Prohibit use of empty blocks + "nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters. + "nonew" : true, // true: Prohibit use of constructors for side-effects (without assignment) +// "plusplus" : false, // true: Prohibit use of `++` & `--` +// "quotmark" : false, // Quotation mark consistency: +// // false : do nothing (default) +// // true : ensure whatever is used is consistent +// // "single" : require single quotes +// // "double" : require double quotes + "undef" : true, // true: Require all non-global variables to be declared (prevents global leaks) +// "unused" : true, // true: Require all defined variables be used +// "strict" : true, // true: Requires all functions run in ES5 Strict Mode +// "maxparams" : false, // {int} Max number of formal params allowed per function +// "maxdepth" : false, // {int} Max depth of nested blocks (within functions) +// "maxstatements" : false, // {int} Max number statements per function +// "maxcomplexity" : 8, // {int} Max cyclomatic complexity per function +// "maxlen" : 120, // {int} Max number of characters per line +// +// // Relaxing +// "asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons) +// "boss" : false, // true: Tolerate assignments where comparisons would be expected + "debug" : false, // true: Allow debugger statements e.g. browser breakpoints. +// "eqnull" : false, // true: Tolerate use of `== null` +// "es5" : false, // true: Allow ES5 syntax (ex: getters and setters) +// "esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`) +// "moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features) +// // (ex: `for each`, multiple try/catch, function expression…) +// "evil" : false, // true: Tolerate use of `eval` and `new Function()` +// "expr" : false, // true: Tolerate `ExpressionStatement` as Programs +// "funcscope" : false, // true: Tolerate defining variables inside control statements +// "globalstrict" : false, // true: Allow global "use strict" (also enables 'strict') +// "iterator" : false, // true: Tolerate using the `__iterator__` property +// "lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block +// "laxbreak" : false, // true: Tolerate possibly unsafe line breakings +// "laxcomma" : false, // true: Tolerate comma-first style coding +// "loopfunc" : false, // true: Tolerate functions being defined in loops +// "multistr" : false, // true: Tolerate multi-line strings +// "noyield" : false, // true: Tolerate generator functions with no yield statement in them. +// "notypeof" : false, // true: Tolerate invalid typeof operator values +// "proto" : false, // true: Tolerate using the `__proto__` property +// "scripturl" : false, // true: Tolerate script-targeted URLs +// "shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;` +// "sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation +// "supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;` +// "validthis" : false, // true: Tolerate using this in a non-constructor function +// +// // Environments +// "browser" : true, // Web Browser (window, document, etc) +// "browserify" : false, // Browserify (node.js code in the browser) +// "couch" : false, // CouchDB +// "devel" : true, // Development/debugging (alert, confirm, etc) +// "dojo" : false, // Dojo Toolkit +// "jasmine" : false, // Jasmine +// "jquery" : false, // jQuery +// "mocha" : true, // Mocha +// "mootools" : false, // MooTools + "node" : true, // Node.js +// "nonstandard" : false, // Widely adopted globals (escape, unescape, etc) +// "prototypejs" : false, // Prototype and Scriptaculous +// "qunit" : false, // QUnit +// "rhino" : false, // Rhino +// "shelljs" : false, // ShellJS +// "worker" : false, // Web Workers +// "wsh" : false, // Windows Scripting Host +// "yui" : false, // Yahoo User Interface + + // Custom Globals + "globals" : { // additional predefined global variables + "suite": true, + "suiteSetup": true, + "test": true, + "suiteTeardown": true + } +} diff --git a/Makefile b/Makefile index 12c9bee6..c1c5a4ac 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,10 @@ test: config/environments/test.js test/acceptance/*.js \ test/acceptance/cache/*.js +jshint: + @echo "***jshint***" + @./node_modules/.bin/jshint lib/ + check: test .PHONY: pre-install test diff --git a/package.json b/package.json index 27f4c317..af48512b 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ }, "devDependencies": { "mocha": "~1.21.4", + "jshint": "~2.6.0", "redis": "~0.8.6", "strftime": "~0.8.2", "semver": "~1.1.4" From fda8afdaf220c4ebf0dca4193020023536cac371 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Sun, 15 Mar 2015 23:44:45 +0100 Subject: [PATCH 02/17] jshint: fix Bad line breaking --- lib/cartodb/api/query_tables_api.js | 6 +++--- lib/cartodb/cartodb_windshaft.js | 4 ++-- lib/cartodb/controllers/template_maps.js | 16 +++++++--------- lib/cartodb/server_options.js | 11 +++++------ lib/cartodb/sql/sql_api.js | 6 +++--- lib/cartodb/template_maps.js | 6 ++---- 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/lib/cartodb/api/query_tables_api.js b/lib/cartodb/api/query_tables_api.js index f4795b05..57a3172e 100644 --- a/lib/cartodb/api/query_tables_api.js +++ b/lib/cartodb/api/query_tables_api.js @@ -138,7 +138,7 @@ function prepareSql(sql) { function shouldQueryPostgresDirectly() { - return global.environment - && global.environment.enabledFeatures - && global.environment.enabledFeatures.cdbQueryTablesFromPostgres; + return global.environment && + global.environment.enabledFeatures && + global.environment.enabledFeatures.cdbQueryTablesFromPostgres; } diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 477a4c24..7d1d2d9a 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -18,8 +18,8 @@ var CartodbWindshaft = function(serverOptions) { } } - var redisPool = serverOptions.redis.pool - || require('redis-mpool')(_.extend(global.environment.redis, {name: 'windshaft:cartodb'})); + var redisPool = serverOptions.redis.pool || + require('redis-mpool')(_.extend(global.environment.redis, {name: 'windshaft:cartodb'})); var cartoData = require('cartodb-redis')({pool: redisPool}); diff --git a/lib/cartodb/controllers/template_maps.js b/lib/cartodb/controllers/template_maps.js index 5b61ae56..f683412d 100644 --- a/lib/cartodb/controllers/template_maps.js +++ b/lib/cartodb/controllers/template_maps.js @@ -100,8 +100,7 @@ TemplateMapsController.prototype.update = function(req, res) { tpl_id = req.params.template_id.split('@'); if ( tpl_id.length > 1 ) { if ( tpl_id[0] != cdbuser ) { - err = new Error("Invalid template id '" - + req.params.template_id + "' for user '" + cdbuser + "'"); + err = new Error("Invalid template id '" + req.params.template_id + "' for user '" + cdbuser + "'"); err.http_status = 404; throw err; } @@ -158,8 +157,8 @@ TemplateMapsController.prototype.retrieve = function(req, res) { tpl_id = req.params.template_id.split('@'); if ( tpl_id.length > 1 ) { if ( tpl_id[0] != cdbuser ) { - var err = new Error("Cannot get template id '" - + req.params.template_id + "' for user '" + cdbuser + "'"); + var err = new Error("Cannot get template id '" + req.params.template_id + "' for user '" + cdbuser + + "'"); err.http_status = 404; throw err; } @@ -220,8 +219,8 @@ TemplateMapsController.prototype.destroy = function(req, res) { tpl_id = req.params.template_id.split('@'); if ( tpl_id.length > 1 ) { if ( tpl_id[0] != cdbuser ) { - var err = new Error("Cannot find template id '" - + req.params.template_id + "' for user '" + cdbuser + "'"); + var err = new Error("Cannot find template id '" + req.params.template_id + "' for user '" + + cdbuser + "'"); err.http_status = 404; throw err; } @@ -361,9 +360,8 @@ TemplateMapsController.prototype.instantiateTemplate = function(req, res, templa var tpl_id = req.params.template_id.split('@'); if ( tpl_id.length > 1 ) { if ( tpl_id[0] && tpl_id[0] != cdbuser ) { - var err = new Error('Cannot instanciate map of user "' - + tpl_id[0] + '" on database of user "' - + cdbuser + '"'); + var err = new Error('Cannot instanciate map of user "' + tpl_id[0] + '" on database of user "' + cdbuser + + '"'); err.http_status = 403; callback(err); return; diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index e0011795..da71e5c8 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -35,8 +35,8 @@ var REQUEST_QUERY_PARAMS_WHITELIST = [ ]; module.exports = function(redisPool) { - redisPool = redisPool - || require('redis-mpool')(_.extend(global.environment.redis, {name: 'windshaft:server_options'})); + redisPool = redisPool || + require('redis-mpool')(_.extend(global.environment.redis, {name: 'windshaft:server_options'})); var cartoData = require('cartodb-redis')({ pool: redisPool }), lzmaWorker = new LZMA(), @@ -377,14 +377,13 @@ module.exports = function(redisPool) { var host = req.headers.host; var mat = host.match(this.re_userFromHost); if ( ! mat ) { - console.error("ERROR: user pattern '" + this.re_userFromHost - + "' does not match hostname '" + host + "'"); + console.error("ERROR: user pattern '" + this.re_userFromHost + "' does not match hostname '" + host + "'"); return; } // console.log("Matches: "); console.dir(mat); if ( ! mat.length === 2 ) { - console.error("ERROR: pattern '" + this.re_userFromHost - + "' gave unexpected matches against '" + host + "': " + mat); + console.error("ERROR: pattern '" + this.re_userFromHost + "' gave unexpected matches against '" + host + "': " + + mat); return; } return mat[1]; diff --git a/lib/cartodb/sql/sql_api.js b/lib/cartodb/sql/sql_api.js index 44c831e2..d5f742f9 100644 --- a/lib/cartodb/sql/sql_api.js +++ b/lib/cartodb/sql/sql_api.js @@ -36,11 +36,11 @@ module.exports.query = function (username, api_key, sql, callback) { var reqSpec = { url:sqlapi, json:true, - headers:{host: sqlapihostname} + headers:{host: sqlapihostname}, // http://nodejs.org/api/http.html#http_agent_maxsockets - ,pool:{maxSockets:maxSockets} + pool:{maxSockets:maxSockets}, // timeout in milliseconds - ,timeout:maxSQLTime + timeout:maxSQLTime }; if ( sql.length > maxGetLen ) { reqSpec.method = 'POST'; diff --git a/lib/cartodb/template_maps.js b/lib/cartodb/template_maps.js index 164161a8..ab46ecc9 100644 --- a/lib/cartodb/template_maps.js +++ b/lib/cartodb/template_maps.js @@ -450,16 +450,14 @@ o.instance = function(template, params) { else if ( type === 'number' ) { // check it's a number if ( typeof(val) !== 'number' && ! val.match(_reNumber) ) { - throw new Error("Invalid number value for template parameter '" - + k + "': " + val); + throw new Error("Invalid number value for template parameter '" + k + "': " + val); } } else if ( type === 'css_color' ) { // check it only contains letters or // starts with # and only contains hexdigits if ( ! val.match(_reCSSColorName) && ! val.match(_reCSSColorVal) ) { - throw new Error("Invalid css_color value for template parameter '" - + k + "': " + val); + throw new Error("Invalid css_color value for template parameter '" + k + "': " + val); } } else { From d03a2c64a6a06b1bfe8dd5ee702efa61a58d763e Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Sun, 15 Mar 2015 23:46:59 +0100 Subject: [PATCH 03/17] jshint: fix Missing semicolon --- lib/cartodb/cache_validator.js | 2 +- lib/cartodb/cartodb_windshaft.js | 2 +- lib/cartodb/server_options.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cartodb/cache_validator.js b/lib/cartodb/cache_validator.js index 22793603..b974e094 100644 --- a/lib/cartodb/cache_validator.js +++ b/lib/cartodb/cache_validator.js @@ -23,4 +23,4 @@ function invalidate_db(dbname, table) { module.exports = { init: init, invalidate_db: invalidate_db -} +}; diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 7d1d2d9a..524d572f 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -31,7 +31,7 @@ var CartodbWindshaft = function(serverOptions) { serverOptions.afterStateChange = function(req, data, callback) { Cache.invalidate_db(req.params.dbname, req.params.table); callback(null, data); - } + }; } serverOptions.beforeStateChange = function(req, callback) { diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index da71e5c8..93f08e09 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -287,7 +287,7 @@ module.exports = function(redisPool) { } requestMapConfig.layers = layers; - return callback(null, requestMapConfig, datasource) + return callback(null, requestMapConfig, datasource); }); }; @@ -558,7 +558,7 @@ module.exports = function(redisPool) { //console.log("type of req.query.lzma is " + typeof(req.query.lzma)); // Decode (from base64) - var lzma = (new Buffer(req.query.lzma, 'base64').toString('binary')).split('').map(function(c) { return c.charCodeAt(0) - 128 }); + var lzma = (new Buffer(req.query.lzma, 'base64').toString('binary')).split('').map(function(c) { return c.charCodeAt(0) - 128; }); // Decompress lzmaWorker.decompress( From e561f77d4d7b343b8b13f2a7820654c418352d1c Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Sun, 15 Mar 2015 23:49:32 +0100 Subject: [PATCH 04/17] jshint: fix Dot notation --- lib/cartodb/backends/pg_connection.js | 4 ++-- lib/cartodb/cartodb_windshaft.js | 4 ++-- lib/cartodb/template_maps.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/cartodb/backends/pg_connection.js b/lib/cartodb/backends/pg_connection.js index 37209b98..6688e00c 100644 --- a/lib/cartodb/backends/pg_connection.js +++ b/lib/cartodb/backends/pg_connection.js @@ -30,7 +30,7 @@ PgConnection.prototype.setDBAuth = function(username, params, callback) { }, function(err, user_id) { if (err) throw err; - user_params['user_id'] = user_id; + user_params.user_id = user_id; var dbuser = _.template(auth_user, user_params); _.extend(params, {dbuser:dbuser}); @@ -42,7 +42,7 @@ PgConnection.prototype.setDBAuth = function(username, params, callback) { }, function(err, user_password) { if (err) throw err; - user_params['user_password'] = user_password; + user_params.user_password = user_password; if ( auth_pass ) { var dbpass = _.template(auth_pass, user_params); _.extend(params, {dbpassword:dbpass}); diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 524d572f..53f731f7 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -5,8 +5,8 @@ var Cache = require('./cache_validator'); var os = require('os'); var HealthCheck = require('./monitoring/health_check'); -if ( ! process.env['PGAPPNAME'] ) - process.env['PGAPPNAME']='cartodb_tiler'; +if ( ! process.env.PGAPPNAME ) + process.env.PGAPPNAME='cartodb_tiler'; var CartodbWindshaft = function(serverOptions) { // Perform keyword substitution in statsd diff --git a/lib/cartodb/template_maps.js b/lib/cartodb/template_maps.js index ab46ecc9..520266a2 100644 --- a/lib/cartodb/template_maps.js +++ b/lib/cartodb/template_maps.js @@ -56,7 +56,7 @@ var o = TemplateMaps.prototype; //--------------- PRIVATE METHODS -------------------------------- o._userTemplateLimit = function() { - return this.opts['max_user_templates'] || 0; + return this.opts.max_user_templates || 0; }; /** From bd1c24ee1c7fe6c5eb0889cd12cb5beeb9347ab3 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Sun, 15 Mar 2015 23:52:46 +0100 Subject: [PATCH 05/17] jshint: Remove Confusing use of '!' --- lib/cartodb/server_options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index 93f08e09..8c50a0d1 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -381,7 +381,7 @@ module.exports = function(redisPool) { return; } // console.log("Matches: "); console.dir(mat); - if ( ! mat.length === 2 ) { + if ( mat.length !== 2 ) { console.error("ERROR: pattern '" + this.re_userFromHost + "' gave unexpected matches against '" + host + "': " + mat); return; From 438ecd5598bc37376461bde2d82b97ec45434b33 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Sun, 15 Mar 2015 23:56:14 +0100 Subject: [PATCH 06/17] jshint: fix Function declarations should not be placed in blocks --- .jshintrc | 2 +- lib/cartodb/cartodb_windshaft.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.jshintrc b/.jshintrc index 767df861..2b7a9367 100644 --- a/.jshintrc +++ b/.jshintrc @@ -8,7 +8,7 @@ // "bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.) // "camelcase" : false, // true: Identifiers must be in camelCase // "curly" : true, // true: Require {} for every new block or scope - "eqeqeq" : true, // true: Require triple equals (===) for comparison +// "eqeqeq" : true, // true: Require triple equals (===) for comparison "forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty() "freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc. "immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());` diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 53f731f7..82da2d68 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -54,15 +54,15 @@ var CartodbWindshaft = function(serverOptions) { varnishHttpCacheBackend = new VarnishHttpCacheBackend(serverOptions.varnish_host, serverOptions.varnish_http_port), surrogateKeysCache = new SurrogateKeysCache(varnishHttpCacheBackend); - if (serverOptions.varnish_purge_enabled) { - function invalidateNamedMap(owner, templateName) { - surrogateKeysCache.invalidate(new NamedMapsCacheEntry(owner, templateName), function(err) { - if (err) { - console.warn('Cache: surrogate key invalidation failed'); - } - }); - } + function invalidateNamedMap (owner, templateName) { + surrogateKeysCache.invalidate(new NamedMapsCacheEntry(owner, templateName), function(err) { + if (err) { + console.warn('Cache: surrogate key invalidation failed'); + } + }); + } + if (serverOptions.varnish_purge_enabled) { ['update', 'delete'].forEach(function(eventType) { templateMaps.on(eventType, invalidateNamedMap); }); From 406a1ffb0b40c0a6e4e01b1966da2a66d9881ab8 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Sun, 15 Mar 2015 23:58:12 +0100 Subject: [PATCH 07/17] no global replaceVars func --- lib/cartodb/template_maps.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cartodb/template_maps.js b/lib/cartodb/template_maps.js index 520266a2..e35dcbbf 100644 --- a/lib/cartodb/template_maps.js +++ b/lib/cartodb/template_maps.js @@ -424,14 +424,14 @@ var _reNumber = /^([-+]?[\d\.]?\d+([eE][+-]?\d+)?)$/, _reCSSColorName = /^[a-zA-Z]+$/, _reCSSColorVal = /^#[0-9a-fA-F]{3,6}$/; -_replaceVars = function(str, params) { +function _replaceVars (str, params) { //return _.template(str, params); // lazy way, possibly dangerous // Construct regular expressions for each param Object.keys(params).forEach(function(k) { str = str.replace(new RegExp("<%=\\s*" + k + "\\s*%>", "g"), params[k]); }); return str; -}; +} o.instance = function(template, params) { var all_params = {}; var phold = template.placeholders || {}; From 5df24e7f27da884e7e838d6bf11a572b41a92074 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Sun, 15 Mar 2015 23:58:38 +0100 Subject: [PATCH 08/17] Remove Unreachable 'break' after 'return' --- lib/cartodb/template_maps.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/cartodb/template_maps.js b/lib/cartodb/template_maps.js index e35dcbbf..b9b490f5 100644 --- a/lib/cartodb/template_maps.js +++ b/lib/cartodb/template_maps.js @@ -136,7 +136,6 @@ o._checkInvalidTemplate = function(template) { break; default: return new Error("Unsupported authentication method: " + auth.method); - break; } return false; From d7f5c406450747a5f4d512ffea5d7ddc7c5ea68f Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 16 Mar 2015 00:00:02 +0100 Subject: [PATCH 09/17] Triple === --- lib/cartodb/server_options.js | 4 ++-- lib/cartodb/sql/sql_api.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index 8c50a0d1..e77a544b 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -196,7 +196,7 @@ module.exports = function(redisPool) { // strip out windshaft/mapnik inserted sql if present var sql = req.params.sql.match(/^\((.*)\)\sas\scdbq$/); - sql = (sql != null) ? sql[1] : req.params.sql; + sql = (sql !== null) ? sql[1] : req.params.sql; return sql; }, @@ -596,7 +596,7 @@ module.exports = function(redisPool) { if ( tksplit.length > 1 ) { req.params.signer = tksplit.shift(); if ( ! req.params.signer ) req.params.signer = user; - else if ( req.params.signer != user ) { + else if ( req.params.signer !== user ) { var err = new Error('Cannot use map signature of user "' + req.params.signer + '" on database of user "' + user + '"'); err.http_status = 403; callback(err); diff --git a/lib/cartodb/sql/sql_api.js b/lib/cartodb/sql/sql_api.js index d5f742f9..32885e57 100644 --- a/lib/cartodb/sql/sql_api.js +++ b/lib/cartodb/sql/sql_api.js @@ -16,7 +16,7 @@ module.exports.query = function (username, api_key, sql, callback) { var qs = { q: sql }; // add api_key if given - if (_.isString(api_key) && api_key != '') { qs.api_key = api_key; } + if (_.isString(api_key) && api_key !== '') { qs.api_key = api_key; } // call sql api // From 0a331cee372ff5816a5eef7950ac8c92f6513a69 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 16 Mar 2015 00:03:59 +0100 Subject: [PATCH 10/17] do not redefine vars --- lib/cartodb/controllers/template_maps.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/cartodb/controllers/template_maps.js b/lib/cartodb/controllers/template_maps.js index f683412d..5dd425b2 100644 --- a/lib/cartodb/controllers/template_maps.js +++ b/lib/cartodb/controllers/template_maps.js @@ -157,10 +157,10 @@ TemplateMapsController.prototype.retrieve = function(req, res) { tpl_id = req.params.template_id.split('@'); if ( tpl_id.length > 1 ) { if ( tpl_id[0] != cdbuser ) { - var err = new Error("Cannot get template id '" + req.params.template_id + "' for user '" + cdbuser + - "'"); - err.http_status = 404; - throw err; + var templateNotFoundErr = new Error("Cannot get template id '" + req.params.template_id + + "' for user '" + cdbuser + "'"); + templateNotFoundErr.http_status = 404; + throw templateNotFoundErr; } tpl_id = tpl_id[1]; } @@ -219,10 +219,10 @@ TemplateMapsController.prototype.destroy = function(req, res) { tpl_id = req.params.template_id.split('@'); if ( tpl_id.length > 1 ) { if ( tpl_id[0] != cdbuser ) { - var err = new Error("Cannot find template id '" + req.params.template_id + "' for user '" + - cdbuser + "'"); - err.http_status = 404; - throw err; + var templateNotFoundErr = new Error("Cannot find template id '" + req.params.template_id + + "' for user '" + cdbuser + "'"); + templateNotFoundErr.http_status = 404; + throw templateNotFoundErr; } tpl_id = tpl_id[1]; } From 3c56c1fab3ca3e8ee1c5e75acc09c19029837f30 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 16 Mar 2015 00:05:01 +0100 Subject: [PATCH 11/17] Adds next param --- lib/cartodb/controllers/template_maps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cartodb/controllers/template_maps.js b/lib/cartodb/controllers/template_maps.js index 5dd425b2..d6b6f528 100644 --- a/lib/cartodb/controllers/template_maps.js +++ b/lib/cartodb/controllers/template_maps.js @@ -310,7 +310,7 @@ TemplateMapsController.prototype.instantiate = function(req, res) { ); }; -TemplateMapsController.prototype.options = function(req, res) { +TemplateMapsController.prototype.options = function(req, res, next) { this.app.doCORS(res, "Content-Type"); return next(); }; From 4365c1dbc26aeea4bef45a2a2d5dd37586a56f89 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 16 Mar 2015 00:07:05 +0100 Subject: [PATCH 12/17] Define mapnikXmlParams variable --- lib/cartodb/monitoring/health_check.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cartodb/monitoring/health_check.js b/lib/cartodb/monitoring/health_check.js index 873cd19d..f925c616 100644 --- a/lib/cartodb/monitoring/health_check.js +++ b/lib/cartodb/monitoring/health_check.js @@ -40,7 +40,7 @@ HealthCheck.prototype.check = function(config, callback) { ok: false } }; - mapnikXmlParams = config; + var mapnikXmlParams = config; Step( function getDBParams() { From 336491b54ca9f88c1f122bd37b4134fa73c1db3c Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 16 Mar 2015 00:16:36 +0100 Subject: [PATCH 13/17] Remove unused vars --- .jshintrc | 2 +- lib/cartodb/cache_validator.js | 5 ++--- lib/cartodb/cartodb_windshaft.js | 2 +- lib/cartodb/controllers/template_maps.js | 4 +--- lib/cartodb/monitoring/health_check.js | 9 ++++----- lib/cartodb/server_options.js | 6 ++---- 6 files changed, 11 insertions(+), 17 deletions(-) diff --git a/.jshintrc b/.jshintrc index 2b7a9367..4f460e41 100644 --- a/.jshintrc +++ b/.jshintrc @@ -26,7 +26,7 @@ // // "single" : require single quotes // // "double" : require double quotes "undef" : true, // true: Require all non-global variables to be declared (prevents global leaks) -// "unused" : true, // true: Require all defined variables be used + "unused" : true, // true: Require all defined variables be used // "strict" : true, // true: Requires all functions run in ES5 Strict Mode // "maxparams" : false, // {int} Max number of formal params allowed per function // "maxdepth" : false, // {int} Max depth of nested blocks (within functions) diff --git a/lib/cartodb/cache_validator.js b/lib/cartodb/cache_validator.js index b974e094..4b3f2181 100644 --- a/lib/cartodb/cache_validator.js +++ b/lib/cartodb/cache_validator.js @@ -1,6 +1,5 @@ -var _ = require('underscore'), - Varnish = require('node-varnish'), - varnish_queue = null; +var Varnish = require('node-varnish'); +var varnish_queue = null; function init(host, port, secret) { varnish_queue = new Varnish.VarnishQueue(host, port, secret); diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 82da2d68..41255f9d 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -127,7 +127,7 @@ var CartodbWindshaft = function(serverOptions) { //console.log("Adding cache channel to route\n" + req.route.path + " not matching any in:\n" + mapCreateRoutes.join("\n")); serverOptions.addCacheChannel(that, req, this); }, - function sendResponse(err, added) { + function sendResponse(err/*, added*/) { if ( err ) console.log(err + err.stack); ws_sendResponse.apply(that, thatArgs); return null; diff --git a/lib/cartodb/controllers/template_maps.js b/lib/cartodb/controllers/template_maps.js index d6b6f528..c23d86a9 100644 --- a/lib/cartodb/controllers/template_maps.js +++ b/lib/cartodb/controllers/template_maps.js @@ -141,7 +141,6 @@ TemplateMapsController.prototype.retrieve = function(req, res) { this.app.doCORS(res); var cdbuser = this.serverOptions.userByReq(req); - var template; var tpl_id; Step( function checkPerms(){ @@ -203,7 +202,6 @@ TemplateMapsController.prototype.destroy = function(req, res) { this.app.doCORS(res); var cdbuser = this.serverOptions.userByReq(req); - var template; var tpl_id; Step( function checkPerms(){ @@ -228,7 +226,7 @@ TemplateMapsController.prototype.destroy = function(req, res) { } self.templateMaps.delTemplate(cdbuser, tpl_id, this); }, - function prepareResponse(err, tpl_val){ + function prepareResponse(err/*, tpl_val*/){ if ( err ) throw err; return { status: 'ok' }; }, diff --git a/lib/cartodb/monitoring/health_check.js b/lib/cartodb/monitoring/health_check.js index f925c616..9e239583 100644 --- a/lib/cartodb/monitoring/health_check.js +++ b/lib/cartodb/monitoring/health_check.js @@ -1,8 +1,7 @@ -var _ = require('underscore'), - dot = require('dot'), - fs = require('fs'), - path = require('path'), - Step = require('step'); +var dot = require('dot'); +var fs = require('fs'); +var path = require('path'); +var Step = require('step'); function HealthCheck(metadataBackend, tilelive) { this.metadataBackend = metadataBackend; diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index e77a544b..cf1f383c 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -573,7 +573,7 @@ module.exports = function(redisPool) { callback(new Error('Error parsing lzma as JSON: ' + err)); } }, - function(percent) { // progress + function(/*percent*/) { // progress //console.log("LZMA decompression " + percent + "%"); } ); @@ -603,7 +603,7 @@ module.exports = function(redisPool) { return; } if ( tksplit.length > 1 ) { - var template_hash = tksplit.shift(); // unused + /*var template_hash = */tksplit.shift(); // unused } req.params.token = tksplit.shift(); //console.log("Request for token " + req.params.token + " with signature from " + req.params.signer); @@ -616,8 +616,6 @@ module.exports = function(redisPool) { // for cartodb, ensure interactivity is cartodb_id or user specified req.params.interactivity = req.params.interactivity || 'cartodb_id'; - var that = this; - if (req.profiler) req.profiler.done('req2params.setup'); Step( From 8c09dfd230b077ea5a913db5b69e9b3a1b0a3f92 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 16 Mar 2015 00:21:55 +0100 Subject: [PATCH 14/17] No capitalize step --- .jshintrc | 2 +- lib/cartodb/api/query_tables_api.js | 6 +++--- lib/cartodb/backends/pg_connection.js | 6 +++--- lib/cartodb/cartodb_windshaft.js | 8 ++++---- lib/cartodb/controllers/template_maps.js | 20 ++++++++++---------- lib/cartodb/monitoring/health_check.js | 4 ++-- lib/cartodb/server_options.js | 18 +++++++++--------- lib/cartodb/template_maps.js | 18 +++++++++--------- 8 files changed, 41 insertions(+), 41 deletions(-) diff --git a/.jshintrc b/.jshintrc index 4f460e41..30101b4c 100644 --- a/.jshintrc +++ b/.jshintrc @@ -14,7 +14,7 @@ "immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());` // "indent" : 4, // {int} Number of spaces to use for indentation // "latedef" : false, // true: Require variables/functions to be defined before being used -// "newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()` + "newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()` "noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee` // "noempty" : true, // true: Prohibit use of empty blocks "nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters. diff --git a/lib/cartodb/api/query_tables_api.js b/lib/cartodb/api/query_tables_api.js index 57a3172e..1db18489 100644 --- a/lib/cartodb/api/query_tables_api.js +++ b/lib/cartodb/api/query_tables_api.js @@ -1,6 +1,6 @@ var sqlApi = require('../sql/sql_api'); var PSQL = require('cartodb-psql'); -var Step = require('step'); +var step = require('step'); function QueryTablesApi(pgConnection, metadataBackend) { this.pgConnection = pgConnection; @@ -78,7 +78,7 @@ QueryTablesApi.prototype.runQuery = function(username, query, queryHandler, call var params = {}; - Step( + step( function setAuth() { self.pgConnection.setDBAuth(username, params, this); }, @@ -109,7 +109,7 @@ QueryTablesApi.prototype.runQuery = function(username, query, queryHandler, call } else { - Step( + step( function getApiKey() { self.metadataBackend.getUserMapKey(username, this); }, diff --git a/lib/cartodb/backends/pg_connection.js b/lib/cartodb/backends/pg_connection.js index 6688e00c..7e4aad15 100644 --- a/lib/cartodb/backends/pg_connection.js +++ b/lib/cartodb/backends/pg_connection.js @@ -1,4 +1,4 @@ -var Step = require('step'); +var step = require('step'); var _ = require('underscore'); function PgConnection(metadataBackend) { @@ -24,7 +24,7 @@ PgConnection.prototype.setDBAuth = function(username, params, callback) { var user_params = {}; var auth_user = global.environment.postgres_auth_user; var auth_pass = global.environment.postgres_auth_pass; - Step( + step( function getId() { self.metadataBackend.getUserId(username, this); }, @@ -76,7 +76,7 @@ PgConnection.prototype.setDBConn = function(dbowner, params, callback) { dbhost: global.environment.postgres.host, dbport: global.environment.postgres.port }); - Step( + step( function getConnectionParams() { self.metadataBackend.getUserDBConnectionParams(dbowner, this); }, diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 41255f9d..bc797948 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -1,5 +1,5 @@ var _ = require('underscore'); -var Step = require('step'); +var step = require('step'); var Windshaft = require('windshaft'); var Cache = require('./cache_validator'); var os = require('os'); @@ -102,7 +102,7 @@ var CartodbWindshaft = function(serverOptions) { } } var req = res.req; - Step ( + step ( function addCacheChannel() { if ( ! req ) { // having no associated request can happen when @@ -172,7 +172,7 @@ var CartodbWindshaft = function(serverOptions) { */ ws.get(serverOptions.base_url + '/infowindow', function(req, res){ ws.doCORS(res); - Step( + step( function(){ serverOptions.getInfowindow(req, this); }, @@ -193,7 +193,7 @@ var CartodbWindshaft = function(serverOptions) { */ ws.get(serverOptions.base_url + '/map_metadata', function(req, res){ ws.doCORS(res); - Step( + step( function(){ serverOptions.getMapMetadata(req, this); }, diff --git a/lib/cartodb/controllers/template_maps.js b/lib/cartodb/controllers/template_maps.js index c23d86a9..452f7225 100644 --- a/lib/cartodb/controllers/template_maps.js +++ b/lib/cartodb/controllers/template_maps.js @@ -1,4 +1,4 @@ -var Step = require('step'); +var step = require('step'); var _ = require('underscore'); function TemplateMapsController(app, serverOptions, templateMaps, metadataBackend, templateBaseUrl, surrogateKeysCache, @@ -35,7 +35,7 @@ TemplateMapsController.prototype.create = function(req, res) { var cdbuser = self.serverOptions.userByReq(req); - Step( + step( function checkPerms(){ self.serverOptions.authorizedByAPIKey(req, this); }, @@ -83,7 +83,7 @@ TemplateMapsController.prototype.update = function(req, res) { var cdbuser = this.serverOptions.userByReq(req); var template; var tpl_id; - Step( + step( function checkPerms(){ self.serverOptions.authorizedByAPIKey(req, this); }, @@ -142,7 +142,7 @@ TemplateMapsController.prototype.retrieve = function(req, res) { var cdbuser = this.serverOptions.userByReq(req); var tpl_id; - Step( + step( function checkPerms(){ self.serverOptions.authorizedByAPIKey(req, this); }, @@ -203,7 +203,7 @@ TemplateMapsController.prototype.destroy = function(req, res) { var cdbuser = this.serverOptions.userByReq(req); var tpl_id; - Step( + step( function checkPerms(){ self.serverOptions.authorizedByAPIKey(req, this); }, @@ -256,7 +256,7 @@ TemplateMapsController.prototype.list = function(req, res) { var cdbuser = this.serverOptions.userByReq(req); - Step( + step( function checkPerms(){ self.serverOptions.authorizedByAPIKey(req, this); }, @@ -296,7 +296,7 @@ TemplateMapsController.prototype.instantiate = function(req, res) { if ( req.profiler && req.profiler.statsd_client) { req.profiler.start('windshaft-cartodb.instance_template_post'); } - Step( + step( function() { if ( ! req.headers['content-type'] || req.headers['content-type'].split(';')[0] != 'application/json') { throw new Error('template POST data must be of type application/json, it is instead '); @@ -323,7 +323,7 @@ TemplateMapsController.prototype.jsonp = function(req, res) { if ( req.profiler && req.profiler.statsd_client) { req.profiler.start('windshaft-cartodb.instance_template_get'); } - Step( + step( function() { if ( req.query.callback === undefined || req.query.callback.length === 0) { throw new Error('callback parameter should be present and be a function name'); @@ -367,7 +367,7 @@ TemplateMapsController.prototype.instantiateTemplate = function(req, res, templa tpl_id = tpl_id[1]; } var auth_token = req.query.auth_token; - Step( + step( function getTemplate(){ self.templateMaps.getTemplate(cdbuser, tpl_id, this); }, @@ -460,7 +460,7 @@ TemplateMapsController.prototype.finish_instantiation = function(err, response, TemplateMapsController.prototype.setDBParams = function(cdbuser, params, callback) { var self = this; - Step( + step( function setAuth() { self.pgConnection.setDBAuth(cdbuser, params, this); }, diff --git a/lib/cartodb/monitoring/health_check.js b/lib/cartodb/monitoring/health_check.js index 9e239583..930f20a4 100644 --- a/lib/cartodb/monitoring/health_check.js +++ b/lib/cartodb/monitoring/health_check.js @@ -1,7 +1,7 @@ var dot = require('dot'); var fs = require('fs'); var path = require('path'); -var Step = require('step'); +var step = require('step'); function HealthCheck(metadataBackend, tilelive) { this.metadataBackend = metadataBackend; @@ -41,7 +41,7 @@ HealthCheck.prototype.check = function(config, callback) { }; var mapnikXmlParams = config; - Step( + step( function getDBParams() { startTime = Date.now(); self.metadataBackend.getAllUserDBParams(config.username, this); diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index cf1f383c..4daacc4b 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -1,5 +1,5 @@ var _ = require('underscore'); -var Step = require('step'); +var step = require('step'); var QueryTablesApi = require('./api/query_tables_api'); var PgConnection = require('./backends/pg_connection'); var crypto = require('crypto'); @@ -147,7 +147,7 @@ module.exports = function(redisPool) { var that = this; - Step ( + step ( function checkCached() { if ( me.channelCache.hasOwnProperty(cacheKey) ) { callback(null, me.channelCache[cacheKey]); @@ -167,7 +167,7 @@ module.exports = function(redisPool) { } var next = this; var mapStore = app.mapStore; - Step( + step( function loadFromStore() { mapStore.load(req.params.token, this); }, @@ -333,7 +333,7 @@ module.exports = function(redisPool) { var dbName = req.params.dbname; var cacheKey = dbName + ':' + token; - Step( + step( function getAffectedTablesAndLastUpdatedTime() { queryTablesApi.getAffectedTablesAndLastUpdatedTime(username, sql, this); }, @@ -444,7 +444,7 @@ module.exports = function(redisPool) { } //console.log("given ApiKey: " + givenKey); var user = me.userByReq(req); - Step( + step( function (){ cartoData.getUserMapKey(user, this); }, @@ -468,7 +468,7 @@ module.exports = function(redisPool) { var that = this; var user = me.userByReq(req); - Step( + step( function (){ that.authorizedByAPIKey(req, this); }, @@ -618,7 +618,7 @@ module.exports = function(redisPool) { if (req.profiler) req.profiler.done('req2params.setup'); - Step( + step( function getPrivacy(){ me.authorize(req, this); }, @@ -671,7 +671,7 @@ module.exports = function(redisPool) { var that = this; var user = me.userByReq(req); - Step( + step( function(){ // TODO: if this step really needed ? that.req2params(req, this); @@ -699,7 +699,7 @@ module.exports = function(redisPool) { var that = this; var user = me.userByReq(req); - Step( + step( function(){ // TODO: if this step really needed ? that.req2params(req, this); diff --git a/lib/cartodb/template_maps.js b/lib/cartodb/template_maps.js index b9b490f5..d7b7f66b 100644 --- a/lib/cartodb/template_maps.js +++ b/lib/cartodb/template_maps.js @@ -1,7 +1,7 @@ -var crypto = require('crypto'), - Step = require('step'), - _ = require('underscore'), - dot = require('dot'); +var crypto = require('crypto'); +var step = require('step'); +var _ = require('underscore'); +var dot = require('dot'); var EventEmitter = require('events').EventEmitter; @@ -71,7 +71,7 @@ o._redisCmd = function(redisFunc, redisArgs, callback) { var that = this; var db = that.db_signatures; - Step( + step( function getRedisClient() { that.redis_pool.acquire(db, this); }, @@ -204,7 +204,7 @@ o.addTemplate = function(owner, template, callback) { var userTemplatesKey = this.key_usr_tpl({ owner:owner }); var limit = this._userTemplateLimit(); - Step( + step( function checkLimit() { if ( ! limit ) { return 0; @@ -252,7 +252,7 @@ o.addTemplate = function(owner, template, callback) { // o.delTemplate = function(owner, tpl_id, callback) { var self = this; - Step( + step( function deleteTemplate() { self._redisCmd('HDEL', [ self.key_usr_tpl({ owner:owner }), tpl_id ], this); }, @@ -310,7 +310,7 @@ o.updTemplate = function(owner, tpl_id, template, callback) { var userTemplatesKey = this.key_usr_tpl({ owner:owner }); - Step( + step( function getExistingTemplate() { self._redisCmd('HGET', [ userTemplatesKey, tpl_id ], this); }, @@ -365,7 +365,7 @@ o.listTemplates = function(owner, callback) { // o.getTemplate = function(owner, tpl_id, callback) { var self = this; - Step( + step( function getTemplate() { self._redisCmd('HGET', [ self.key_usr_tpl({owner:owner}), tpl_id ], this); }, From 645a2cd4420c0f44da92fb08f5304ee1f70b73ad Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 16 Mar 2015 00:27:14 +0100 Subject: [PATCH 15/17] 120 chars lines --- .jshintrc | 4 ++-- lib/cartodb/cartodb_windshaft.js | 11 ++++++++--- lib/cartodb/server_options.js | 29 +++++++++++++++++++---------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/.jshintrc b/.jshintrc index 30101b4c..74f558f1 100644 --- a/.jshintrc +++ b/.jshintrc @@ -31,8 +31,8 @@ // "maxparams" : false, // {int} Max number of formal params allowed per function // "maxdepth" : false, // {int} Max depth of nested blocks (within functions) // "maxstatements" : false, // {int} Max number statements per function -// "maxcomplexity" : 8, // {int} Max cyclomatic complexity per function -// "maxlen" : 120, // {int} Max number of characters per line +// "maxcomplexity" : 6, // {int} Max cyclomatic complexity per function + "maxlen" : 120, // {int} Max number of characters per line // // // Relaxing // "asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons) diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index bc797948..28e5c40d 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -26,7 +26,8 @@ var CartodbWindshaft = function(serverOptions) { var templateMaps = serverOptions.templateMaps; if(serverOptions.cache_enabled) { - console.log("cache invalidation enabled, varnish on ", serverOptions.varnish_host, ' ', serverOptions.varnish_port); + console.log("cache invalidation enabled, varnish on ", serverOptions.varnish_host, ' ', + serverOptions.varnish_port); Cache.init(serverOptions.varnish_host, serverOptions.varnish_port, serverOptions.varnish_secret); serverOptions.afterStateChange = function(req, data, callback) { Cache.invalidate_db(req.params.dbname, req.params.table); @@ -51,7 +52,10 @@ var CartodbWindshaft = function(serverOptions) { var SurrogateKeysCache = require('./cache/surrogate_keys_cache'), NamedMapsCacheEntry = require('./cache/model/named_maps_entry'), VarnishHttpCacheBackend = require('./cache/backend/varnish_http'), - varnishHttpCacheBackend = new VarnishHttpCacheBackend(serverOptions.varnish_host, serverOptions.varnish_http_port), + varnishHttpCacheBackend = new VarnishHttpCacheBackend( + serverOptions.varnish_host, + serverOptions.varnish_http_port + ), surrogateKeysCache = new SurrogateKeysCache(varnishHttpCacheBackend); function invalidateNamedMap (owner, templateName) { @@ -124,7 +128,8 @@ var CartodbWindshaft = function(serverOptions) { //console.log("Skipping cache channel in route:\n" + req.route.path); return false; } -//console.log("Adding cache channel to route\n" + req.route.path + " not matching any in:\n" + mapCreateRoutes.join("\n")); +//console.log("Adding cache channel to route\n" + req.route.path + " not matching any in:\n" + +// mapCreateRoutes.join("\n")); serverOptions.addCacheChannel(that, req, this); }, function sendResponse(err/*, added*/) { diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index 4daacc4b..92e04f4a 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -281,14 +281,16 @@ module.exports = function(redisPool) { }; me.beforeLayergroupCreate = function(req, requestMapConfig, callback) { - mapConfigNamedLayersAdapter.getLayers(this.userByReq(req), requestMapConfig.layers, pgConnection, function(err, layers, datasource) { - if (err) { - return callback(err); - } + mapConfigNamedLayersAdapter.getLayers(this.userByReq(req), requestMapConfig.layers, pgConnection, + function(err, layers, datasource) { + if (err) { + return callback(err); + } - requestMapConfig.layers = layers; - return callback(null, requestMapConfig, datasource); - }); + requestMapConfig.layers = layers; + return callback(null, requestMapConfig, datasource); + } + ); }; me.afterLayergroupCreate = function(req, mapconfig, response, callback) { @@ -408,7 +410,8 @@ module.exports = function(redisPool) { var layergroup_id = req.params.token; var auth_token = req.params.auth_token; - //console.log("Checking authorization from signer " + signer + " for resource " + layergroup_id + " with auth_token " + auth_token); + //console.log("Checking authorization from signer " + signer + " for resource " + layergroup_id + + // " with auth_token " + auth_token); var mapStore = req.app.mapStore; if (!mapStore) { throw new Error('Unable to retrieve map configuration token'); @@ -558,7 +561,12 @@ module.exports = function(redisPool) { //console.log("type of req.query.lzma is " + typeof(req.query.lzma)); // Decode (from base64) - var lzma = (new Buffer(req.query.lzma, 'base64').toString('binary')).split('').map(function(c) { return c.charCodeAt(0) - 128; }); + var lzma = new Buffer(req.query.lzma, 'base64') + .toString('binary') + .split('') + .map(function(c) { + return c.charCodeAt(0) - 128; + }); // Decompress lzmaWorker.decompress( @@ -597,7 +605,8 @@ module.exports = function(redisPool) { req.params.signer = tksplit.shift(); if ( ! req.params.signer ) req.params.signer = user; else if ( req.params.signer !== user ) { - var err = new Error('Cannot use map signature of user "' + req.params.signer + '" on database of user "' + user + '"'); + var err = new Error('Cannot use map signature of user "' + req.params.signer + '" on database of user "' + + user + '"'); err.http_status = 403; callback(err); return; From b6d3785599b6fe7404213fca7561598c4ca29c41 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 16 Mar 2015 00:36:38 +0100 Subject: [PATCH 16/17] Fix Max cyclomatic complexity value --- .jshintrc | 2 +- lib/cartodb/server_options.js | 1 + lib/cartodb/template_maps.js | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.jshintrc b/.jshintrc index 74f558f1..e8d605fc 100644 --- a/.jshintrc +++ b/.jshintrc @@ -31,7 +31,7 @@ // "maxparams" : false, // {int} Max number of formal params allowed per function // "maxdepth" : false, // {int} Max depth of nested blocks (within functions) // "maxstatements" : false, // {int} Max number statements per function -// "maxcomplexity" : 6, // {int} Max cyclomatic complexity per function + "maxcomplexity" : 8, // {int} Max cyclomatic complexity per function "maxlen" : 120, // {int} Max number of characters per line // // // Relaxing diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index 92e04f4a..ff052586 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -547,6 +547,7 @@ module.exports = function(redisPool) { ); }; + // jshint maxcomplexity:10 /** * Whitelist input and get database name & default geometry type from * subdomain/user metadata held in CartoDB Redis diff --git a/lib/cartodb/template_maps.js b/lib/cartodb/template_maps.js index d7b7f66b..c10bf0f6 100644 --- a/lib/cartodb/template_maps.js +++ b/lib/cartodb/template_maps.js @@ -89,6 +89,7 @@ o._redisCmd = function(redisFunc, redisArgs, callback) { }; var _reValidIdentifier = /^[a-zA-Z][0-9a-zA-Z_]*$/; +// jshint maxcomplexity:15 o._checkInvalidTemplate = function(template) { if ( template.version != '0.0.1' ) { return new Error("Unsupported template version " + template.version); From 87782b400d2c6a086988b23db61a12145e91df43 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 16 Mar 2015 00:38:29 +0100 Subject: [PATCH 17/17] jshint to be tested by default --- Makefile | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c1c5a4ac..1d3c1cdd 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,8 @@ jshint: @echo "***jshint***" @./node_modules/.bin/jshint lib/ +test-all: jshint test + check: test .PHONY: pre-install test diff --git a/package.json b/package.json index af48512b..44a6e6f4 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ }, "scripts": { "preinstall": "make pre-install", - "test": "make test" + "test": "make test-all" }, "engines": { "node": ">=0.8 <0.11",