From: marc tobias Date: Sun, 23 Feb 2020 02:17:34 +0000 (+0100) Subject: fix remaining eslint warnings X-Git-Url: https://git.openstreetmap.org/nominatim-ui.git/commitdiff_plain/1df5c38175a3d15f8e595f49506b4dfb46e73d29 fix remaining eslint warnings --- diff --git a/.eslintrc.json b/.eslintrc.json index 6af997f..a3e191f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -33,6 +33,12 @@ } ] } + }, + { + "files": ["handlebar_helpers.js"], + "globals": { + "get_config_value": true + } } ] } diff --git a/package.json b/package.json index 8e9a16b..c9d8485 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "lint": "node node_modules/.bin/eslint --quiet dist/assets/js/nominatim-ui.js" + "lint": "node node_modules/.bin/eslint --quiet src/handlebar_helpers.js dist/assets/js/nominatim-ui.js" }, "author": "", "license": "GPL-3.0", diff --git a/src/assets/js/base.js b/src/assets/js/base.js index 90a3588..98f7ee8 100644 --- a/src/assets/js/base.js +++ b/src/assets/js/base.js @@ -61,10 +61,13 @@ function map_viewbox_as_string() { // ********************************************************* function fetch_from_api(endpoint_name, params, callback) { - // `&a=&b=&c=1` => '&c=' - for (var k in params) { - if (typeof (params[k]) === 'undefined' || params[k] === '' || params[k] === null) { - delete params[k]; + // `&a=&b=&c=1` => '&c=1' + + var param_names = Object.keys(params); + for (var i = 0; i < param_names.length; i += 1) { + var val = param_names[keys[i]]; + if (typeof (val) === 'undefined' || val === '' || val === null) { + delete param_names[keys[i]]; } } diff --git a/src/handlebar_helpers.js b/src/handlebar_helpers.js index 358ac36..e233eb9 100644 --- a/src/handlebar_helpers.js +++ b/src/handlebar_helpers.js @@ -1,3 +1,5 @@ +'use strict'; + function formatOSMType(sType, bExcludeExternal) { if (sType === 'N') return 'node'; if (sType === 'W') return 'way'; @@ -12,7 +14,7 @@ function formatOSMType(sType, bExcludeExternal) { } Handlebars.registerHelper({ - shortOSMType: function(sType) { + shortOSMType: function (sType) { if (sType === 'node') return 'N'; if (sType === 'way') return 'W'; if (sType === 'relation') return 'R'; @@ -99,7 +101,7 @@ Handlebars.registerHelper({ return (iLevel < 15 ? iLevel : ''); }, formatMapIcon: function (sIcon) { - if (!sIcon) return; + if (!sIcon) return ''; var url = sIcon; if (!url.match(/^http/)) url = get_config_value('Images_Base_Url') + url; @@ -117,7 +119,8 @@ Handlebars.registerHelper({ if (aPlace.type && aPlace.type === 'yes' && aPlace.class) { return capitalize(aPlace.class.replace(/_/g, ' ')); - } else if (aPlace.type) { + } + if (aPlace.type) { return capitalize(aPlace.type.replace(/_/g, ' ')); } return ''; @@ -146,13 +149,10 @@ Handlebars.registerHelper({ return 'other: ' + iRank; }, tooManyHierarchyLinesWarning: function (aPlace) { - if (!aPlace.hierarchy) return; + if (!aPlace.hierarchy) return ''; - var c = 0; - for (var type in aPlace.hierarchy) { - c = c + type.length + 1; - } - if (c < 500) return; + var c = Object.keys(aPlace.hierarchy); + if (c < 500) return ''; return new Handlebars.SafeString( '

There are more child objects which are not shown.

' @@ -186,7 +186,9 @@ Handlebars.registerHelper({ var select = $('