From 9c6c63c167fb14a25f5fb790faf1b0a86654d62a Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Wed, 15 Jul 2015 15:03:28 +0200 Subject: [PATCH] More strict jshint --- .jshintrc | 4 +- lib/cartodb/api/auth_api.js | 2 +- lib/cartodb/backends/pg_connection.js | 10 +- lib/cartodb/backends/template_maps.js | 26 +- lib/cartodb/controllers/layergroup.js | 2 - lib/cartodb/controllers/named_maps_admin.js | 4 +- .../models/mapconfig/named_map_provider.js | 2 +- test/acceptance/multilayer.js | 261 +++++++---- test/acceptance/server.js | 2 +- test/acceptance/templates.js | 434 ++++++++++++------ test/unit/cartodb/template_maps.test.js | 76 +-- 11 files changed, 540 insertions(+), 283 deletions(-) diff --git a/.jshintrc b/.jshintrc index f03eef65..8972be0b 100644 --- a/.jshintrc +++ b/.jshintrc @@ -7,8 +7,8 @@ // // 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 + "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 () { } ());` diff --git a/lib/cartodb/api/auth_api.js b/lib/cartodb/api/auth_api.js index 5b20cbf4..68533fe9 100644 --- a/lib/cartodb/api/auth_api.js +++ b/lib/cartodb/api/auth_api.js @@ -72,7 +72,7 @@ AuthApi.prototype.authorizedByAPIKey = function(user, req, callback) { }, function checkApiKey(err, val){ assert.ifError(err); - return val && givenKey == val; + return val && givenKey === val; }, function finish(err, authorized) { callback(err, authorized); diff --git a/lib/cartodb/backends/pg_connection.js b/lib/cartodb/backends/pg_connection.js index 6cc432fb..2ca56f5b 100644 --- a/lib/cartodb/backends/pg_connection.js +++ b/lib/cartodb/backends/pg_connection.js @@ -37,7 +37,9 @@ PgConnection.prototype.setDBAuth = function(username, params, callback) { // skip looking up user_password if postgres_auth_pass // doesn't contain the "user_password" label - if (!auth_pass || ! auth_pass.match(/\buser_password\b/) ) return null; + if (!auth_pass || ! auth_pass.match(/\buser_password\b/) ) { + return null; + } self.metadataBackend.getUserDBPass(username, this); }, @@ -84,10 +86,12 @@ PgConnection.prototype.setDBConn = function(dbowner, params, callback) { function extendParams(err, dbParams){ assert.ifError(err); // we don't want null values or overwrite a non public user - if (params.dbuser != 'publicuser' || !dbParams.dbuser) { + if (params.dbuser !== 'publicuser' || !dbParams.dbuser) { delete dbParams.dbuser; } - if ( dbParams ) _.extend(params, dbParams); + if ( dbParams ) { + _.extend(params, dbParams); + } return null; }, function finish(err) { diff --git a/lib/cartodb/backends/template_maps.js b/lib/cartodb/backends/template_maps.js index 544bdf1f..b550cb53 100644 --- a/lib/cartodb/backends/template_maps.js +++ b/lib/cartodb/backends/template_maps.js @@ -22,7 +22,9 @@ var util = require('util'); // // function TemplateMaps(redis_pool, opts) { - if (!(this instanceof TemplateMaps)) return new TemplateMaps(); + if (!(this instanceof TemplateMaps)) { + return new TemplateMaps(); + } EventEmitter.call(this); @@ -83,7 +85,9 @@ o._redisCmd = function(redisFunc, redisArgs, callback) { redisClient[redisFunc.toUpperCase()].apply(redisClient, redisArgs); }, function releaseRedisClient(err, data) { - if ( ! _.isUndefined(redisClient) ) that.redis_pool.release(db, redisClient); + if ( ! _.isUndefined(redisClient) ) { + that.redis_pool.release(db, redisClient); + } callback(err, data); } ); @@ -93,7 +97,7 @@ var _reValidNameIdentifier = /^[a-z0-9][0-9a-z_\-]*$/i; var _reValidPlaceholderIdentifier = /^[a-z][0-9a-z_]*$/i; // jshint maxcomplexity:15 o._checkInvalidTemplate = function(template) { - if ( template.version != '0.0.1' ) { + if ( template.version !== '0.0.1' ) { return new Error("Unsupported template version " + template.version); } var tplname = template.name; @@ -132,10 +136,12 @@ o._checkInvalidTemplate = function(template) { case 'open': break; case 'token': - if ( ! _.isArray(auth.valid_tokens) ) + if ( ! _.isArray(auth.valid_tokens) ) { return new Error("Invalid 'token' authentication: missing valid_tokens"); - if ( ! auth.valid_tokens.length ) + } + if ( ! auth.valid_tokens.length ) { return new Error("Invalid 'token' authentication: no valid_tokens"); + } break; default: return new Error("Unsupported authentication method: " + auth.method); @@ -301,7 +307,7 @@ o.updTemplate = function(owner, tpl_id, template, callback) { var templateName = template.name; - if ( tpl_id != templateName ) { + if ( tpl_id !== templateName ) { return callback(new Error("Cannot update name of a map template ('" + tpl_id + "' != '" + templateName + "')")); } @@ -463,8 +469,12 @@ o.instance = function(template, params) { var layergroup = JSON.parse(JSON.stringify(template.layergroup)); for (var i=0; i