From 69a13e91057c40a33a83a0cfed044a508b794fc2 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Tue, 2 Dec 2014 11:39:24 -0500 Subject: [PATCH] fixing all the js lint related issues (lintified) --- controller/suggest.js | 2 +- helper/geojsonify.js | 6 +- helper/outputGenerator.js | 2 +- index.js | 6 +- sanitiser/_id.js | 8 +- sanitiser/_layers.js | 6 +- sanitiser/_size.js | 2 +- sanitiser/doc.js | 2 +- sanitiser/reverse.js | 2 +- sanitiser/suggest.js | 2 +- service/suggest.js | 2 +- test/unit/controller/suggest.js | 21 ++- test/unit/controller/suggest_nearby.js | 7 +- test/unit/helper/geojsonify.js | 242 ++++++++++++------------- test/unit/helper/outputSchema.js | 9 +- test/unit/query/search.js | 54 +++--- test/unit/sanitiser/doc.js | 4 +- test/unit/sanitiser/suggest.js | 10 +- test/unit/service/mget.js | 2 +- test/unit/service/search.js | 2 +- test/unit/service/suggest.js | 2 +- 21 files changed, 210 insertions(+), 183 deletions(-) diff --git a/controller/suggest.js b/controller/suggest.js index f39f89d7..914a8652 100644 --- a/controller/suggest.js +++ b/controller/suggest.js @@ -35,7 +35,7 @@ function setup( backend, query ){ var dedup = function(combined) { var unique_ids = []; return combined.filter(function(item, pos) { - if (unique_ids.indexOf(item.text) == -1) { + if (unique_ids.indexOf(item.text) === -1) { unique_ids.push(item.text); return true; } diff --git a/helper/geojsonify.js b/helper/geojsonify.js index 84fb9d08..e28a617c 100644 --- a/helper/geojsonify.js +++ b/helper/geojsonify.js @@ -16,7 +16,7 @@ function search( docs ){ var geodata = docs.map( function( doc ){ // something went very wrong - if( !doc ) return warning(); + if( !doc ) { return warning(); } var output = {}; @@ -26,12 +26,12 @@ function search( docs ){ output.layer = doc._type; // map center_point - if( !doc.center_point ) return warning(); + if( !doc.center_point ) { return warning(); } output.lat = parseFloat( doc.center_point.lat ); output.lng = parseFloat( doc.center_point.lon ); // map name - if( !doc.name || !doc.name.default ) return warning(); + if( !doc.name || !doc.name.default ) { return warning(); } output.name = doc.name.default; // map admin values diff --git a/helper/outputGenerator.js b/helper/outputGenerator.js index 42fa1279..53ae1fb1 100644 --- a/helper/outputGenerator.js +++ b/helper/outputGenerator.js @@ -30,7 +30,7 @@ module.exports = function( record ){ // de-dupe outputs outputs = outputs.filter( function( i, pos ) { - return outputs.indexOf( i ) == pos; + return outputs.indexOf( i ) === pos; }); return outputs.join(', ').trim(); diff --git a/index.js b/index.js index fe6c73b9..2e2e47bf 100644 --- a/index.js +++ b/index.js @@ -5,13 +5,13 @@ var cluster = require('cluster'), port = ( process.env.PORT || 3100 ); /** cluster webserver across all cores **/ -if( multicore ){ +// if( multicore ){ // @todo: not finished yet // cluster(app) // .use(cluster.stats()) // .listen( process.env.PORT || 3100 ); -} -else { +// } +if (!multicore){ console.log( 'listening on ' + port ); app.listen( process.env.PORT || 3100 ); } diff --git a/sanitiser/_id.js b/sanitiser/_id.js index 073e1824..b19f0696 100644 --- a/sanitiser/_id.js +++ b/sanitiser/_id.js @@ -18,7 +18,7 @@ function sanitize( req ){ return { 'error': true, 'message': message || ('invalid param \''+ fieldname + '\': text length, must be >0') - } + }; }; if(('string' === typeof params.id && !params.id.length) || params.id === undefined){ @@ -31,7 +31,7 @@ function sanitize( req ){ // de-dupe params.ids = params.ids.filter(function(item, pos) { - return params.ids.indexOf(item) == pos; + return params.ids.indexOf(item) === pos; }); for (var i=0; i0' }, + defaultLengthError = function(input) { return 'invalid param \''+ input + '\': text length, must be >0'; }, defaultFormatError = 'invalid: must be of the format type:id for ex: \'geoname:4163334\'', defaultError = 'invalid param \'id\': text length, must be >0', defaultMissingTypeError = function(input) { var type = input.split(delimiter)[0]; - return type + ' is invalid. It must be one of these values - [' + indeces.join(", ") + ']'}, + return type + ' is invalid. It must be one of these values - [' + indeces.join(', ') + ']'; }, defaultClean = { ids: [ { id: '123', type: 'geoname' } ] }, sanitize = function(query, cb) { _sanitize({'query':query}, cb); }, inputs = { diff --git a/test/unit/sanitiser/suggest.js b/test/unit/sanitiser/suggest.js index 52096be2..28ec175e 100644 --- a/test/unit/sanitiser/suggest.js +++ b/test/unit/sanitiser/suggest.js @@ -3,8 +3,14 @@ var suggest = require('../../../sanitiser/suggest'), _sanitize = suggest.sanitize, middleware = suggest.middleware, defaultError = 'invalid param \'input\': text length, must be >0', - defaultClean = { input: 'test', lat: 0, layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood' ], lon: 0, size: 10, zoom: 10 }, - sanitize = function(query, cb) { _sanitize({'query':query}, cb); } + defaultClean = { input: 'test', + lat: 0, + layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood' ], + lon: 0, + size: 10, + zoom: 10 + }, + sanitize = function(query, cb) { _sanitize({'query':query}, cb); }; module.exports.tests = {}; diff --git a/test/unit/service/mget.js b/test/unit/service/mget.js index f62eeae0..9f13d78b 100644 --- a/test/unit/service/mget.js +++ b/test/unit/service/mget.js @@ -40,7 +40,7 @@ module.exports.tests.functional_success = function(test, common) { data.forEach(function(d) { t.true(typeof d === 'object', 'valid object'); }); - t.deepEqual(data, expected, 'values correctly mapped') + t.deepEqual(data, expected, 'values correctly mapped'); t.end(); }); }); diff --git a/test/unit/service/search.js b/test/unit/service/search.js index 0768dff1..e1f97541 100644 --- a/test/unit/service/search.js +++ b/test/unit/service/search.js @@ -42,7 +42,7 @@ module.exports.tests.functional_success = function(test, common) { data.forEach(function(d) { t.true(typeof d === 'object', 'valid object'); }); - t.deepEqual(data, expected, 'values correctly mapped') + t.deepEqual(data, expected, 'values correctly mapped'); t.end(); }); }); diff --git a/test/unit/service/suggest.js b/test/unit/service/suggest.js index 5ae120a0..a058b57e 100644 --- a/test/unit/service/suggest.js +++ b/test/unit/service/suggest.js @@ -30,7 +30,7 @@ module.exports.tests.functional_success = function(test, common) { data.forEach(function(d) { t.true(typeof d === 'object', 'valid object'); }); - t.deepEqual(data, expected, 'values correctly mapped') + t.deepEqual(data, expected, 'values correctly mapped'); t.end(); }); });