diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 00000000..3c3629e6 --- /dev/null +++ b/.jshintignore @@ -0,0 +1 @@ +node_modules diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..eabec8cd --- /dev/null +++ b/.jshintrc @@ -0,0 +1,21 @@ +{ + "node": true, + "curly": true, + "eqeqeq": true, + "freeze": true, + "immed": true, + "indent": 2, + "latedef": false, + "newcap": true, + "noarg": true, + "noempty": true, + "nonbsp": true, + "nonew": true, + "plusplus": false, + "quotmark": "single", + "undef": true, + "unused": false, + "maxparams": 4, + "maxdepth": 4, + "maxlen": 140 +} 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/package.json b/package.json index 6ef30cc1..46c326df 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,8 @@ }, "devDependencies": { "ciao": "^0.3.4", + "jshint": "^2.5.6", + "precommit-hook": "^1.0.7", "tape": "^2.13.4", "tap-spec": "^0.2.0", "nsp": "^0.3.0" 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(); }); });