Browse Source

fixing all the js lint related issues (lintified)

pull/49/head
Harish Krishna 10 years ago
parent
commit
69a13e9105
  1. 2
      controller/suggest.js
  2. 6
      helper/geojsonify.js
  3. 2
      helper/outputGenerator.js
  4. 6
      index.js
  5. 8
      sanitiser/_id.js
  6. 6
      sanitiser/_layers.js
  7. 2
      sanitiser/_size.js
  8. 2
      sanitiser/doc.js
  9. 2
      sanitiser/reverse.js
  10. 2
      sanitiser/suggest.js
  11. 2
      service/suggest.js
  12. 21
      test/unit/controller/suggest.js
  13. 7
      test/unit/controller/suggest_nearby.js
  14. 242
      test/unit/helper/geojsonify.js
  15. 9
      test/unit/helper/outputSchema.js
  16. 54
      test/unit/query/search.js
  17. 4
      test/unit/sanitiser/doc.js
  18. 10
      test/unit/sanitiser/suggest.js
  19. 2
      test/unit/service/mget.js
  20. 2
      test/unit/service/search.js
  21. 2
      test/unit/service/suggest.js

2
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;
}

6
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

2
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();

6
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 );
}

8
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; i<params.ids.length; i++) {
@ -55,8 +55,8 @@ function sanitize( req ){
return errormessage(thisparam);
}
// type text must be one of the indeces
if(indeces.indexOf(type) == -1){
return errormessage('type', type + ' is invalid. It must be one of these values - [' + indeces.join(", ") + ']');
if(indeces.indexOf(type) === -1){
return errormessage('type', type + ' is invalid. It must be one of these values - [' + indeces.join(', ') + ']');
}
req.clean.ids.push({
id: id,

6
sanitiser/_layers.js

@ -25,7 +25,7 @@ function sanitize( req ){
return {
'error': true,
'message': 'invalid param \'layer\': must be one or more of ' + alias_indeces.join(',')
}
};
}
}
var expand_aliases = function(alias, layers, layer_indeces) {
@ -35,14 +35,14 @@ function sanitize( req ){
layers = layers.concat(layer_indeces);
}
return layers;
}
};
layers = expand_aliases('poi', layers, ['geoname','osmnode','osmway']);
layers = expand_aliases('admin', layers, ['admin0','admin1','admin2','neighborhood']);
// de-dup
layers = layers.filter(function(item, pos) {
return layers.indexOf(item) == pos;
return layers.indexOf(item) === pos;
});
clean.layers = layers;

2
sanitiser/_size.js

@ -4,7 +4,7 @@ function sanitize( req, default_size){
var clean = req.clean || {};
var params= req.query;
var default_size = default_size || 10;
default_size = default_size || 10;
// ensure the input params are a valid object
if( Object.prototype.toString.call( params ) !== '[object Object]' ){

2
sanitiser/doc.js

@ -5,7 +5,7 @@ var logger = require('../src/logger'),
id: require('../sanitiser/_id')
};
var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); }
var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); };
// export sanitize for testing
module.exports.sanitize = sanitize;

2
sanitiser/reverse.js

@ -9,7 +9,7 @@ var logger = require('../src/logger'),
}
};
var sanitize = function(req, cb) { _sanitize(req, sanitiser, cb); }
var sanitize = function(req, cb) { _sanitize(req, sanitiser, cb); };
// export sanitize for testing
module.exports.sanitize = sanitize;

2
sanitiser/suggest.js

@ -8,7 +8,7 @@ var logger = require('../src/logger'),
latlonzoom: require('../sanitiser/_latlonzoom')
};
var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); }
var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); };
// export sanitize for testing
module.exports.sanitize = sanitize;

2
service/suggest.js

@ -16,7 +16,7 @@ function service( backend, cmd, cb ){
// map returned documents
var docs = [];
if( data && Array.isArray( data.pelias ) && data.pelias.length ){
docs = data['pelias'][0].options || [];
docs = data.pelias[0].options || [];
}
// fire callback

21
test/unit/controller/suggest.js

@ -55,10 +55,20 @@ module.exports.tests.functional_success = function(test, common) {
var backend = mockBackend( 'client/suggest/ok/1', function( cmd ){
// the backend executes suggest (vanilla and admin-only) and mget, so we check them all based on cmd
if( cmd.body.docs ){
t.deepEqual(cmd, { body: { docs: [ { _id: 'mockid1', _index: 'pelias', _type: 'mocktype' } , { _id: 'mockid2', _index: 'pelias', _type: 'mocktype' }] } }, 'correct mget command');
t.deepEqual(cmd, {
body: { docs: [
{ _id: 'mockid1', _index: 'pelias', _type: 'mocktype' },
{ _id: 'mockid2', _index: 'pelias', _type: 'mocktype' }
]}
}, 'correct mget command');
} else if (cmd.body.layers) {
// layers are set exclusively for admin: test for admin-only layers
t.deepEqual(cmd, { body: { input: 'b', layers: [ 'admin0', 'admin1', 'admin2' ] }, index: 'pelias' }, 'correct suggest/admin command');
t.deepEqual(cmd, {
body: {
input: 'b',
layers: [ 'admin0', 'admin1', 'admin2' ]
}, index: 'pelias'
}, 'correct suggest/admin command');
} else {
t.deepEqual(cmd, { body: { input: 'b' }, index: 'pelias' }, 'correct suggest command');
}
@ -87,7 +97,12 @@ module.exports.tests.functional_failure = function(test, common) {
test('functional failure', function(t) {
var backend = mockBackend( 'client/suggest/fail/1', function( cmd ){
if( cmd.body.docs ){
t.deepEqual(cmd, { body: { docs: [ { _id: 'mockid1', _index: 'pelias', _type: 'mocktype' } , { _id: 'mockid2', _index: 'pelias', _type: 'mocktype' }] } }, 'correct mget command');
t.deepEqual(cmd, {
body: { docs: [
{ _id: 'mockid1', _index: 'pelias', _type: 'mocktype' },
{ _id: 'mockid2', _index: 'pelias', _type: 'mocktype' }]
}
}, 'correct mget command');
} else if (cmd.body.layers) {
// layers are set exclusively for admin: test for admin-only layers
t.deepEqual(cmd, { body: { a: 'b', layers: [ 'admin0', 'admin1', 'admin2' ] }, index: 'pelias' }, 'correct suggest/admin command');

7
test/unit/controller/suggest_nearby.js

@ -58,7 +58,12 @@ module.exports.tests.functional_success = function(test, common) {
if( ++i === 1 ){
t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias' }, 'correct suggest command');
} else {
t.deepEqual(cmd, { body: { docs: [ { _id: 'mockid1', _index: 'pelias', _type: 'mocktype' }, { _id: 'mockid2', _index: 'pelias', _type: 'mocktype' } ] } }, 'correct mget command');
t.deepEqual(cmd, {
body: { docs: [
{ _id: 'mockid1', _index: 'pelias', _type: 'mocktype' },
{ _id: 'mockid2', _index: 'pelias', _type: 'mocktype' } ]
}
}, 'correct mget command');
}
});
var controller = setup( backend, mockQuery() );

242
test/unit/helper/geojsonify.js

@ -15,167 +15,167 @@ module.exports.tests.search = function(test, common) {
var input = [
{
"_id": "id1",
"_type": "type1",
"center_point": {
"lat": 51.5337144,
"lon": -0.1069716
'_id': 'id1',
'_type': 'type1',
'center_point': {
'lat': 51.5337144,
'lon': -0.1069716
},
"name": {
"default": "'Round Midnight Jazz and Blues Bar"
'name': {
'default': '\'Round Midnight Jazz and Blues Bar'
},
"type": "node",
"address": {
"number": "13",
"street": "Liverpool Road",
"zip": "N1 0RW"
'type': 'node',
'address': {
'number': '13',
'street': 'Liverpool Road',
'zip': 'N1 0RW'
},
"alpha3": "GBR",
"admin0": "United Kingdom",
"admin1": "Islington",
"admin1_abbr": "ISL",
"admin2": "Angel",
"local_admin": "test1",
"locality": "test2",
"neighborhood": "test3",
"suggest": {
"input": [
"'round midnight jazz and blues bar"
'alpha3': 'GBR',
'admin0': 'United Kingdom',
'admin1': 'Islington',
'admin1_abbr': 'ISL',
'admin2': 'Angel',
'local_admin': 'test1',
'locality': 'test2',
'neighborhood': 'test3',
'suggest': {
'input': [
'\'round midnight jazz and blues bar'
],
"output": "osmnode:2208150035"
'output': 'osmnode:2208150035'
}
},
{
"_id": "id2",
"_type": "type2",
"type": "way",
"name": {
"default": "Blues Cafe"
'_id': 'id2',
'_type': 'type2',
'type': 'way',
'name': {
'default': 'Blues Cafe'
},
"center_point": {
"lat": "51.517806",
"lon": "-0.101795"
'center_point': {
'lat': '51.517806',
'lon': '-0.101795'
},
"alpha3": "GBR",
"admin0": "United Kingdom",
"admin1": "City And County Of The City Of London",
"admin1_abbr": "COL",
"admin2": "Smithfield",
"local_admin": "test1",
"locality": "test2",
"neighborhood": "test3",
"suggest": {
"input": [
"blues cafe"
'alpha3': 'GBR',
'admin0': 'United Kingdom',
'admin1': 'City And County Of The City Of London',
'admin1_abbr': 'COL',
'admin2': 'Smithfield',
'local_admin': 'test1',
'locality': 'test2',
'neighborhood': 'test3',
'suggest': {
'input': [
'blues cafe'
],
"output": "osmway:147495160"
'output': 'osmway:147495160'
}
},
{
"_id": "34633854",
"_type": "osmway",
"type": "osmway",
"name": {
"default": "Empire State Building"
'_id': '34633854',
'_type': 'osmway',
'type': 'osmway',
'name': {
'default': 'Empire State Building'
},
"center_point": {
"lat": "40.748432",
"lon": "-73.985656"
'center_point': {
'lat': '40.748432',
'lon': '-73.985656'
},
"alpha3": "USA",
"admin0": "United States",
"admin1": "New York",
"admin1_abbr": "NY",
"admin2": "New York",
"local_admin": "Manhattan",
"locality": "New York",
"neighborhood": "Koreatown",
"suggest": {
"input": [
"empire state building"
'alpha3': 'USA',
'admin0': 'United States',
'admin1': 'New York',
'admin1_abbr': 'NY',
'admin2': 'New York',
'local_admin': 'Manhattan',
'locality': 'New York',
'neighborhood': 'Koreatown',
'suggest': {
'input': [
'empire state building'
],
"output": "osmway:34633854"
'output': 'osmway:34633854'
}
}
];
var expected = {
"type": "FeatureCollection",
"bbox": [ -0.1069716, 51.517806, -0.101795, 51.5337144 ],
"features": [
'type': 'FeatureCollection',
'bbox': [ -73.985656, 40.748432, -0.101795, 51.5337144 ],
'features': [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
-0.1069716,
51.5337144
]
},
"properties": {
"id": "id1",
"type": "type1",
"layer": "type1",
"text": "'Round Midnight Jazz and Blues Bar, test3, Angel",
"name": "'Round Midnight Jazz and Blues Bar",
"alpha3": "GBR",
"admin0": "United Kingdom",
"admin1": "Islington",
"admin1_abbr": "ISL",
"admin2": "Angel",
"local_admin": "test1",
"locality": "test2",
"neighborhood": "test3"
'properties': {
'id': 'id1',
'type': 'type1',
'layer': 'type1',
'text': '\'Round Midnight Jazz and Blues Bar, test3, Angel',
'name': '\'Round Midnight Jazz and Blues Bar',
'alpha3': 'GBR',
'admin0': 'United Kingdom',
'admin1': 'Islington',
'admin1_abbr': 'ISL',
'admin2': 'Angel',
'local_admin': 'test1',
'locality': 'test2',
'neighborhood': 'test3'
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
-0.101795,
51.517806
]
},
"properties": {
"id": "id2",
"type": "type2",
"layer": "type2",
"text": "Blues Cafe, test3, Smithfield",
"name": "Blues Cafe",
"alpha3": "GBR",
"admin0": "United Kingdom",
"admin1": "City And County Of The City Of London",
"admin1_abbr": "COL",
"admin2": "Smithfield",
"local_admin": "test1",
"locality": "test2",
"neighborhood": "test3"
'properties': {
'id': 'id2',
'type': 'type2',
'layer': 'type2',
'text': 'Blues Cafe, test3, Smithfield',
'name': 'Blues Cafe',
'alpha3': 'GBR',
'admin0': 'United Kingdom',
'admin1': 'City And County Of The City Of London',
'admin1_abbr': 'COL',
'admin2': 'Smithfield',
'local_admin': 'test1',
'locality': 'test2',
'neighborhood': 'test3'
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
-73.985656,
40.748432
]
},
"properties": {
"id": "34633854",
"type": "osmway",
"layer": "osmway",
"text": "Empire State Building, Manhattan, NY",
"name": "Empire State Building",
"alpha3": "USA",
"admin0": "United States",
"admin1": "New York",
"admin1_abbr": "NY",
"admin2": "New York",
"local_admin": "Manhattan",
"locality": "New York",
"neighborhood": "Koreatown"
'properties': {
'id': '34633854',
'type': 'osmway',
'layer': 'osmway',
'text': 'Empire State Building, Manhattan, NY',
'name': 'Empire State Building',
'alpha3': 'USA',
'admin0': 'United States',
'admin1': 'New York',
'admin1_abbr': 'NY',
'admin2': 'New York',
'local_admin': 'Manhattan',
'locality': 'New York',
'neighborhood': 'Koreatown'
}
}
]

9
test/unit/helper/outputSchema.js

@ -21,14 +21,14 @@ module.exports.tests.valid = function(test, common) {
var isValid = function(keys, schema) {
test('valid key/object (' + keys + ')' , function(t) {
if (keys=="default") {
if (keys === 'default') {
t.deepEqual(schema, default_schema, 'valid default schema');
} else {
t.equal(alpha3.hasOwnProperty(keys), true, 'valid key');
}
t.equal(typeof schema, 'object', 'valid object');
t.notEqual(Object.getOwnPropertyNames(schema).length, 0, 'object not empty');
for (levels in schema) {
for (var levels in schema) {
t.equal(Object.prototype.toString.call(schema[levels]), '[object Array]', levels+' is an array');
for (var i=0;i<schema[levels].length;i++) {
var key = schema[levels][i];
@ -37,8 +37,9 @@ module.exports.tests.valid = function(test, common) {
}
t.end();
});
}
for (keys in schemas) {
};
for (var keys in schemas) {
isValid(keys, schemas[keys]);
}
};

54
test/unit/query/search.js

@ -29,29 +29,29 @@ module.exports.tests.query = function(test, common) {
});
var expected = {
"query": {
"filtered": {
"query": {
"query_string": {
"query": "test",
"fields": [
"name.default"
'query': {
'filtered': {
'query': {
'query_string': {
'query': 'test',
'fields': [
'name.default'
],
"default_operator": "OR"
'default_operator': 'OR'
}
},
"filter": {
"bool": {
"must": [
'filter': {
'bool': {
'must': [
{
"geo_distance": {
"distance": "50km",
"distance_type": "plane",
"optimize_bbox": "indexed",
"_cache": true,
"center_point": {
"lat": "29.49",
"lon": "-82.51"
'geo_distance': {
'distance': '50km',
'distance_type': 'plane',
'optimize_bbox': 'indexed',
'_cache': true,
'center_point': {
'lat': '29.49',
'lon': '-82.51'
}
}
}
@ -60,19 +60,19 @@ module.exports.tests.query = function(test, common) {
}
}
},
"sort": [
'sort': [
{
"_geo_distance": {
"center_point": {
"lat": 29.49136,
"lon": -82.50622
'_geo_distance': {
'center_point': {
'lat': 29.49136,
'lon': -82.50622
},
"order": "asc",
"unit": "km"
'order': 'asc',
'unit': 'km'
}
}
],
"size": 10
'size': 10
};
t.deepEqual(query, expected, 'valid search query');

4
test/unit/sanitiser/doc.js

@ -4,12 +4,12 @@ var doc = require('../../../sanitiser/doc'),
middleware = doc.middleware,
indeces = require('../../../query/indeces'),
delimiter = ':',
defaultLengthError = function(input) { return 'invalid param \''+ input + '\': text length, must be >0' },
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 = {

10
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 = {};

2
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();
});
});

2
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();
});
});

2
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();
});
});

Loading…
Cancel
Save