diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 000000000..50f9d76d9 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,34 @@ +{ + "rules": { + "eqeqeq": 0, + "camelcase": 2, + "quotes": [2, "single"], + "no-mixed-spaces-and-tabs": [2, "smart-tabs"], + "space-after-function-name": 2, + "space-in-parens": 2, + "space-in-brackets": 2, + "space-before-blocks": 2, + "space-after-keywords": 2, + "no-lonely-if": 2, + "comma-style": 2, + "indent": 2, + "no-underscore-dangle": 0, + "no-use-before-define": "nofunc", + "no-constant-condition": 0, + "no-multi-spaces": 0, + "strict": 0, + "key-spacing": 0, + "no-shadow": 0 + }, + "globals": { + "dust": true, + "DG": true, + "L": true, + "baron": true, + "module": false, + "define": false + }, + "env": { + "browser": true + } +} diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 636eab7db..000000000 --- a/.jshintrc +++ /dev/null @@ -1,54 +0,0 @@ -{ - "browser": true, - "node": true, - "predef": [], - - "debug": false, - "devel": false, - - "es5": false, - "strict": false, - "globalstrict": false, - - "asi": false, - "laxbreak": false, - "bitwise": true, - "boss": false, - "curly": true, - "eqnull": false, - "evil": false, - "expr": true, - "forin": false, - "immed": true, - "latedef": true, - "loopfunc": false, - "noarg": true, - "regexp": true, - "regexdash": false, - "scripturl": false, - "shadow": false, - "supernew": false, - "undef": true, - "funcscope": false, - - "newcap": true, - "noempty": true, - "nonew": true, - "nomen": false, - "onevar": false, - "plusplus": false, - "sub": false, - "indent": 4, - - "eqeqeq": false, - "trailing": true, - "white": true, - "smarttabs": true, - "globals": { - "L": true, - "DG": true, - "dust": true, - "Promise": true, - "__DETECT_RETINA__": true - } -} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 901361ef2..773d18dc3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -274,7 +274,7 @@ ## Стандарты кодирования ### JavaScript -Основные требования к JavaScript коду обеспечиваются синтаксическим анализатором и описаны в конфигурационом файле [jsHint](https://github.com/2gis/maps-api-2.0/blob/master/.jshintrc). В процессе разработки мы стараемся придерживаться соглашений, схожими с [Airbnb style guide](https://github.com/airbnb/javascript), за исключением соглашений о [пробелах](https://github.com/airbnb/javascript#whitespace) и [комментариях](https://github.com/airbnb/javascript#comments). +Основные требования к JavaScript коду обеспечиваются синтаксическим анализатором и описаны в конфигурационом файле [ESLint](https://github.com/2gis/maps-api-2.0/blob/master/.eslintrc). В процессе разработки мы стараемся придерживаться соглашений, схожими с [Airbnb style guide](https://github.com/airbnb/javascript), за исключением соглашений о [пробелах](https://github.com/airbnb/javascript#whitespace) и [комментариях](https://github.com/airbnb/javascript#comments). ### HTML и CSS #### Определения diff --git a/gulp/tasks/help.js b/gulp/tasks/help.js index 71965bcb5..3f91e8e00 100644 --- a/gulp/tasks/help.js +++ b/gulp/tasks/help.js @@ -3,7 +3,7 @@ var gulp = require('gulp'); gulp.task('help', function () { util.log('Tasks list:'); - util.log('gulp lint # Check JS files for errors with JSHint'); + util.log('gulp lint # Check JS files for errors with ESLint'); util.log('gulp build # Lint, combine and minify source files, update doc, copy assets'); util.log('gulp doc # Generate documentation from .md files'); util.log('gulp test # Rebuild source and run unit tests'); diff --git a/gulp/tasks/lintJS.js b/gulp/tasks/lintJS.js index 16829197c..c8f91480e 100644 --- a/gulp/tasks/lintJS.js +++ b/gulp/tasks/lintJS.js @@ -1,13 +1,11 @@ - +var eslint = require('gulp-eslint'); var gulp = require('gulp'); -var $ = require('gulp-load-plugins')(); var error = require('../util/error'); gulp.task('lintJS', function () { return gulp.src('src/**/src/**/*.js') .pipe(error.handle()) - .pipe($.cache($.jshint('.jshintrc'))) - .pipe($.jshint.reporter('jshint-stylish')) - .pipe($.jshint.reporter('fail')); + .pipe(eslint()) + .pipe(eslint.format()); }); diff --git a/gulp/util/csslint/gulp-csslint.js b/gulp/util/csslint/gulp-csslint.js index 59ec85a36..0c08d7c6c 100644 --- a/gulp/util/csslint/gulp-csslint.js +++ b/gulp/util/csslint/gulp-csslint.js @@ -1,5 +1,3 @@ -/*jshint node:true */ - 'use strict'; var gutil = require('gulp-util'); diff --git a/package.json b/package.json index 2f9b40675..5c4749971 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "gulp-bump": "0.1.13", "gulp-cache": "0.2.4", "gulp-concat": "^2.2.0", + "gulp-eslint": "^0.7.0", "gulp-file": "0.2.0", "gulp-flatten": "0.0.4", "gulp-footer": "^1.0.5", @@ -38,7 +39,6 @@ "gulp-header": "^1.2.2", "gulp-if": "^1.2.5", "gulp-imagemin": "^2.2.0", - "gulp-jshint": "^1.9.2", "gulp-karma": "0.0.4", "gulp-less": "^3.0.0", "gulp-load-plugins": "^0.8.0", @@ -55,7 +55,6 @@ "happen": "0.1.3", "html5shiv": "^3.7.2", "image-size": "0.3.5", - "jshint-stylish": "^1.0.0", "less": "^2.4.0", "lodash": "^2.4.1", "map-stream": "0.1.0", diff --git a/src/DGAjax/src/DGAjax.js b/src/DGAjax/src/DGAjax.js index 370b3ea5f..878d0edf6 100644 --- a/src/DGAjax/src/DGAjax.js +++ b/src/DGAjax/src/DGAjax.js @@ -334,7 +334,7 @@ DG.ajax = (function () { } catch (e) { // can't assign this in IE<=8, just ignore } - /*jshint evil:true */ + /* eslint-disable no-eval */ if (r) { switch (type) { case 'json': @@ -355,7 +355,7 @@ DG.ajax = (function () { break; } } - /*jshint evil:false */ + /* eslint-enable no-eval */ self._responseArgs.resp = resp; complete(resp); } @@ -412,7 +412,12 @@ DG.ajax = (function () { enc = encodeURIComponent, add = function (key, value) { // If value is a function, invoke it and return its value - value = ('function' === typeof value) ? value() : (value ? value : ''); + if (typeof value == 'function') { + value = value(); + } else { + value = value || ''; + } + s[s.length] = enc(key) + '=' + enc(value); }; diff --git a/src/DGAttribution/src/DGAttribution.js b/src/DGAttribution/src/DGAttribution.js index b34625653..705f8175f 100644 --- a/src/DGAttribution/src/DGAttribution.js +++ b/src/DGAttribution/src/DGAttribution.js @@ -6,6 +6,7 @@ DG.Control.Attribution.include({ }, _getLink: function (linkType) { + /* eslint-disable camelcase */ var dictionary = { ru: { copyright_logo: 'http://info.2gis.ru/?utm_source=copyright&utm_medium=map&utm_campaign=partners', @@ -43,6 +44,7 @@ DG.Control.Attribution.include({ copyright_license: 'http://law.2gis.ae/licensing-agreement/' } }; + /* eslint-enable camelcase */ var countryCode = (this._countryCode in dictionary) ? this._countryCode : 'ru'; @@ -106,7 +108,7 @@ DG.Control.Attribution.include({ }, /* global __DGAttribution_TMPL__ */ _tmpl: DG.dust(__DGAttribution_TMPL__), - _getData: function (lang, osm) { + _getData: function (lang) { return { 'osm': this._osm, 'work_on': this.t('work_on'), diff --git a/src/DGCore/src/DGCore.js b/src/DGCore/src/DGCore.js index ac12ca8b0..c0394da5e 100644 --- a/src/DGCore/src/DGCore.js +++ b/src/DGCore/src/DGCore.js @@ -23,12 +23,12 @@ DG.version = window.__dgApi__.version; DG.debug = window.__dgApi__.debug; DG.Icon.Default.imagePath = '../img/vendors/leaflet'; -/* jshint ignore:start */ +/* eslint-disable */ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','__GOOGLE_ANALYTICS__','ga'); -/* jshint ignore:end */ +/* eslint-enable */ /*global ga:false*/ ga('create', '__GA_CODE__', 'none'); @@ -43,7 +43,7 @@ newImg.src = '__ANALYTICS__?' + // Improve IHandler DG.Map.include({ addHandler: function (name, HandlerClass) { - if (!HandlerClass) { return; } + if (!HandlerClass) { return this; } var options = this.options[name], param = (options === Object(options)) ? options : null, @@ -61,5 +61,7 @@ DG.Map.include({ // Apply class to map container for detect when we dont need hover effects DG.Map.addInitHook(function () { - !DG.Browser.touch && DG.DomUtil.addClass(this._container, 'no-touch'); + if (!DG.Browser.touch) { + DG.DomUtil.addClass(this._container, 'no-touch'); + } }); diff --git a/src/DGCore/src/DGthen.js b/src/DGCore/src/DGthen.js index 71cb8c959..d6d82b360 100644 --- a/src/DGCore/src/DGthen.js +++ b/src/DGCore/src/DGthen.js @@ -1,11 +1,11 @@ var handlers = window.__dgApi__.callbacks || [], chain = Promise.resolve(); -//dont pollute global space! +// dont pollute global space! try { delete window.__dgApi__; } catch(e) { - window.__dgApi__ = undefined; //ie8 cant delete from window object + window.__dgApi__ = undefined; // ie8 cant delete from window object } handlers.forEach(function (handlers) { @@ -17,6 +17,8 @@ DG.then = function (resolve, reject) { }; // IE8 throw error if `chain.catch` +/* eslint-disable dot-notation, no-console */ chain['catch'](function(err) { console.error(err); }); +/* eslint-enable dot-notation, no-console */ diff --git a/src/DGCustomization/src/DGCustomization.js b/src/DGCustomization/src/DGCustomization.js index 40d7129c8..2e27a7bb8 100644 --- a/src/DGCustomization/src/DGCustomization.js +++ b/src/DGCustomization/src/DGCustomization.js @@ -1,7 +1,5 @@ //Inject observing localization change -var controlAddTo = DG.Control.prototype.addTo, - panBy = DG.Map.prototype.panBy, - getBoundsZoom = DG.Map.prototype.getBoundsZoom; +var controlAddTo = DG.Control.prototype.addTo; DG.Control.include({ addTo: function (map) { diff --git a/src/DGCustomization/src/DGMap.BaseLayer.js b/src/DGCustomization/src/DGMap.BaseLayer.js index a917a3d0d..7009641de 100644 --- a/src/DGCustomization/src/DGMap.BaseLayer.js +++ b/src/DGCustomization/src/DGMap.BaseLayer.js @@ -12,7 +12,8 @@ DG.Map.addInitHook(function () { this.baseLayer = new BaseLayer('__TILE_SERVER__', { subdomains: '0123', - errorTileUrl: this.getLang() == 'ru' ? errorRuUrl : errorUrl, + errorTileUrl: this.getLang() === 'ru' ? errorRuUrl : errorUrl, + /* global __DETECT_RETINA__ */ detectRetina: __DETECT_RETINA__, maxZoom: 19, maxNativeZoom: 19 @@ -20,7 +21,7 @@ ).addTo(this); this.on('langchange', function(ev) { - if (ev.lang == 'ru') { + if (ev.lang === 'ru') { this.baseLayer.options.errorTileUrl = errorRuUrl; } else { this.baseLayer.options.errorTileUrl = errorUrl; diff --git a/src/DGCustomization/src/DGMap.js b/src/DGCustomization/src/DGMap.js index 6cde52e54..9cbdc4f2c 100644 --- a/src/DGCustomization/src/DGMap.js +++ b/src/DGCustomization/src/DGMap.js @@ -113,7 +113,11 @@ DG.Map.include({ _updateTileLayers: function (e) { if (!(e.layer instanceof DG.TileLayer) || e.layer._isDg) { return; } - e.type === 'layeradd' ? this._tileLayersNumber++ : this._tileLayersNumber--; + if (e.type === 'layeradd') { + this._tileLayersNumber++; + } else { + this._tileLayersNumber--; + } }, _restrictZoom: function (coords) { @@ -128,7 +132,9 @@ DG.Map.include({ if (isMapMaxZoom) { if (!this._mapMaxZoomCache) { this._mapMaxZoomCache = mapOptions.maxZoom; } mapOptions.maxZoom = (this._mapMaxZoomCache && project) ? this._mapMaxZoomCache : '__PROJECT_LEAVE_MAX_ZOOM__'; - project && (this._mapMaxZoomCache = mapOptions.maxZoom); + if (project) { + this._mapMaxZoomCache = mapOptions.maxZoom; + } return mapOptions.maxZoom; } else { diff --git a/src/DGDust/src/DGDust.js b/src/DGDust/src/DGDust.js index d85a05c7a..636d32d40 100644 --- a/src/DGDust/src/DGDust.js +++ b/src/DGDust/src/DGDust.js @@ -14,4 +14,4 @@ DG.dust = function (tmpl) { }; }; -if (DG.debug) { dust.debugLevel = 'ERROR'; } \ No newline at end of file +if (DG.debug) { dust.debugLevel = 'ERROR'; } diff --git a/src/DGEntrance/src/Arrow.js b/src/DGEntrance/src/Arrow.js index c53a3a796..e382327c3 100644 --- a/src/DGEntrance/src/Arrow.js +++ b/src/DGEntrance/src/Arrow.js @@ -1,10 +1,9 @@ DG.Entrance.Arrow = DG.Polyline.extend({ - initialize: function (latlngs, options) { // (Array, Object) + options = options || {}; + this._setLatLngs(latlngs); - /*jshint shadow: true */ - var options = options || {}; - /*jshint shadow: false */ + if (DG.Path.ANIMATION_AVAILABLE) { options.animation = this.getArrowAnimation(this._convertLatLngs(latlngs)); } diff --git a/src/DGEntrance/src/ArrowSVG.VML.js b/src/DGEntrance/src/ArrowSVG.VML.js index 20edfb0ba..cdfec9316 100644 --- a/src/DGEntrance/src/ArrowSVG.VML.js +++ b/src/DGEntrance/src/ArrowSVG.VML.js @@ -28,4 +28,4 @@ DG.Entrance.Arrow.SVG.include(!L.Browser.vml ? {} : { container.style.visibility = options.visibility; } } -}); \ No newline at end of file +}); diff --git a/src/DGEntrance/src/ArrowSVG.js b/src/DGEntrance/src/ArrowSVG.js index 366d23038..5cae7a102 100644 --- a/src/DGEntrance/src/ArrowSVG.js +++ b/src/DGEntrance/src/ArrowSVG.js @@ -35,9 +35,14 @@ DG.Entrance.Arrow.SVG = DG.SVG.extend({ marker.setAttribute('markerUnits', 'userSpaceOnUse'); marker.setAttribute('stroke-width', '0'); - markerStyle.path && marker.appendChild(this._getMarkerChild('path', markerStyle.path, layer)); + if (markerStyle.path) { + marker.appendChild(this._getMarkerChild('path', markerStyle.path, layer)); + } + + if (markerStyle.polygon) { + marker.appendChild(this._getMarkerChild('polygon', markerStyle.polygon, layer)); + } - markerStyle.polygon && marker.appendChild(this._getMarkerChild('polygon', markerStyle.polygon, layer)); layer._markers.push(marker); this._getDefs().appendChild(marker); @@ -115,7 +120,9 @@ L.Map.include({ renderer = this._arrowRenderer = new DG.Entrance.Arrow.SVG(); } - !this.hasLayer(renderer) && this.addLayer(renderer); + if (!this.hasLayer(renderer)) { + this.addLayer(renderer); + } return renderer; } diff --git a/src/DGEntrance/src/DGEntrance.js b/src/DGEntrance/src/DGEntrance.js index cf0a6c0f5..2d6874bda 100644 --- a/src/DGEntrance/src/DGEntrance.js +++ b/src/DGEntrance/src/DGEntrance.js @@ -132,7 +132,7 @@ DG.Entrance = DG.Layer.extend({ }, _isAllowedZoom: function () { - return !(this._map.getZoom() < DG.Entrance.SHOW_FROM_ZOOM); // jshint ignore:line + return this._map.getZoom() >= DG.Entrance.SHOW_FROM_ZOOM; }, _getArrowStrokeOptions: function () { diff --git a/src/DGEntrance/src/PathAnimation.js b/src/DGEntrance/src/PathAnimation.js index 1c46f16d7..dbab9b2a5 100644 --- a/src/DGEntrance/src/PathAnimation.js +++ b/src/DGEntrance/src/PathAnimation.js @@ -34,7 +34,7 @@ DG.Path.include(!DG.Path.ANIMATION_AVAILABLE ? {} : { if (animOptions && points.length > 0) { animationEl = DG.SVG.create('animate'); - //calculate values if attributeName: 'd' was used to animate + // calculate values if attributeName: 'd' was used to animate if (animOptions.getValues) { animOptions.values = animOptions.getValues(points); } @@ -55,7 +55,9 @@ DG.Path.include(!DG.Path.ANIMATION_AVAILABLE ? {} : { _removeAnimation: function (animationEl) { this._map.once('zoomstart', function () { - animationEl && this._path.removeChild(animationEl); + if (animationEl) { + this._path.removeChild(animationEl); + } this._animationEl = null; }, this); } diff --git a/src/DGFullScreen/src/DGFullScreen.js b/src/DGFullScreen/src/DGFullScreen.js index fd01c8807..127944a62 100644 --- a/src/DGFullScreen/src/DGFullScreen.js +++ b/src/DGFullScreen/src/DGFullScreen.js @@ -42,7 +42,9 @@ DG.Control.Fullscreen = DG.RoundControl.extend({ }, _onFullScreenStateChange: function () { - (!DG.screenfull.isFullscreen()) && this._toggle(false, 'exit', 'on', 'cancelfullscreen'); + if (!DG.screenfull.isFullscreen()) { + this._toggle(false, 'exit', 'on', 'cancelfullscreen'); + } } }); diff --git a/src/DGGeoclicker/src/Controller.js b/src/DGGeoclicker/src/Controller.js index 691ecb5cd..75628f17f 100644 --- a/src/DGGeoclicker/src/Controller.js +++ b/src/DGGeoclicker/src/Controller.js @@ -92,11 +92,15 @@ DG.Geoclicker.Controller = DG.Class.extend({ return; } - while (type = this.findHandler(result)) { // jshint ignore:line + type = this.findHandler(result); + + while (type) { if (this._runHandler(type, result)) { return; } delete result[type]; + + type = this.findHandler(result); } this._runHandler('default'); }, diff --git a/src/DGGeoclicker/src/View.js b/src/DGGeoclicker/src/View.js index 7c0066d8a..164f061fb 100644 --- a/src/DGGeoclicker/src/View.js +++ b/src/DGGeoclicker/src/View.js @@ -83,20 +83,14 @@ DG.Geoclicker.View = DG.Class.extend({ _detectCssAnimation: function () { var animation = false, - animationstring = 'animation', - keyframeprefix = '', domPrefixes = 'Webkit Moz O ms Khtml'.split(' '), - elm = document.createElement('div'), - pfx = ''; + elm = document.createElement('div'); if (elm.style.animationName) { animation = true; } if (animation === false) { for (var i = 0; i < domPrefixes.length; i++) { if (elm.style[domPrefixes[i] + 'AnimationName'] !== undefined) { - pfx = domPrefixes[i]; - animationstring = pfx + 'Animation'; - keyframeprefix = '-' + pfx.toLowerCase() + '-'; animation = true; break; } diff --git a/src/DGGeoclicker/src/handler/CityArea.js b/src/DGGeoclicker/src/handler/CityArea.js index 6af428670..c602c8e35 100644 --- a/src/DGGeoclicker/src/handler/CityArea.js +++ b/src/DGGeoclicker/src/handler/CityArea.js @@ -32,7 +32,9 @@ DG.Geoclicker.Handler.CityArea = DG.Geoclicker.Handler.Default.extend({ return false; } - !this._stylesInited && this._initStyles(); + if (!this._stylesInited) { + this._initStyles(); + } this._popup = this._view.getPopup(); diff --git a/src/DGGeoclicker/src/handler/Default.js b/src/DGGeoclicker/src/handler/Default.js index 4578f9f80..206c292ca 100644 --- a/src/DGGeoclicker/src/handler/Default.js +++ b/src/DGGeoclicker/src/handler/Default.js @@ -8,7 +8,7 @@ DG.Geoclicker.Handler.Default = DG.Class.extend({ _eventHandlers: {}, - initialize: function (controller, view, map, options) { // (Object, Object, Object, Object) + initialize: function (controller, view, map) { // (Object, Object, Object) this._controller = controller; this._view = view; this._map = map; @@ -57,7 +57,7 @@ DG.Geoclicker.Handler.Default = DG.Class.extend({ 'center': this._map.getCenter().lng + ',' + this._map.getCenter().lat, 'zoom': this._map.getZoom(), 'name': encodeURIComponent(name), - 'rsType': this._map.projectDetector.getProject().transport ? 'bus' : 'car' , + 'rsType': this._map.projectDetector.getProject().transport ? 'bus' : 'car', 'point': this._popup._latlng.lng + ',' + this._popup._latlng.lat }); }, diff --git a/src/DGGeoclicker/src/handler/Handler.js b/src/DGGeoclicker/src/handler/Handler.js index 2807e92d1..0a817b6cb 100644 --- a/src/DGGeoclicker/src/handler/Handler.js +++ b/src/DGGeoclicker/src/handler/Handler.js @@ -1 +1 @@ -DG.Geoclicker.Handler = {}; \ No newline at end of file +DG.Geoclicker.Handler = {}; diff --git a/src/DGGeoclicker/src/handler/House.View.js b/src/DGGeoclicker/src/handler/House.View.js index b9252020a..cf95456c6 100644 --- a/src/DGGeoclicker/src/handler/House.View.js +++ b/src/DGGeoclicker/src/handler/House.View.js @@ -93,12 +93,14 @@ DG.Geoclicker.Handler.House.include({ btns.push(this._getShowAllData(houseFilials.count)); } - this._isRouteSearchAllowed() && btns.push({ - name: 'goto', - label: this.t('go_to'), - icon: true, - href: this._directionsUrl - }); + if (this._isRouteSearchAllowed()) { + btns.push({ + name: 'goto', + label: this.t('go_to'), + icon: true, + href: this._directionsUrl + }); + } return this._view.render({ tmpl: 'popupFooterBtns', diff --git a/src/DGGeoclicker/src/handler/Sight.js b/src/DGGeoclicker/src/handler/Sight.js index 1dc458d44..685ae14c3 100644 --- a/src/DGGeoclicker/src/handler/Sight.js +++ b/src/DGGeoclicker/src/handler/Sight.js @@ -15,7 +15,6 @@ DG.Geoclicker.Handler.Sight = DG.Geoclicker.Handler.Default.extend({ var attraction = results.attraction, data = {}, self = this, - abbr, footer = { btns: [ { diff --git a/src/DGGeoclicker/src/provider/CatalogApi.js b/src/DGGeoclicker/src/provider/CatalogApi.js index 2a0a2dd48..104b7675c 100644 --- a/src/DGGeoclicker/src/provider/CatalogApi.js +++ b/src/DGGeoclicker/src/provider/CatalogApi.js @@ -39,10 +39,12 @@ DG.Geoclicker.Provider.CatalogApi = DG.Class.extend({ firmsInHouse: function (houseId, parameters) { // (String, Function, Number) parameters = parameters || {}; + /* eslint-disable camelcase */ var params = DG.extend(this.options.data, { building_id: houseId, page: parameters.page || 1 }); + /* eslint-enable camelcase */ return this._performRequest(params, this.options.urlFirmsInHouse); }, @@ -56,12 +58,14 @@ DG.Geoclicker.Provider.CatalogApi = DG.Class.extend({ }, geoSearch: function (q, types, zoomlevel) { // (String, String, Number) + /* eslint-disable camelcase */ var params = { point: q, type: types, zoom_level: zoomlevel, fields: this.options.geoFields }; + /* eslint-enable camelcase */ return this._performRequest(params, this.options.urlGeoSearch); }, diff --git a/src/DGGeoclicker/src/provider/Provider.js b/src/DGGeoclicker/src/provider/Provider.js index 883dafbd7..d93e3131f 100644 --- a/src/DGGeoclicker/src/provider/Provider.js +++ b/src/DGGeoclicker/src/provider/Provider.js @@ -1 +1 @@ -DG.Geoclicker.Provider = {}; \ No newline at end of file +DG.Geoclicker.Provider = {}; diff --git a/src/DGMeta/src/DGMeta.Layer.js b/src/DGMeta/src/DGMeta.Layer.js index d07062d23..6b91f470b 100644 --- a/src/DGMeta/src/DGMeta.Layer.js +++ b/src/DGMeta/src/DGMeta.Layer.js @@ -152,7 +152,7 @@ DG.Meta.Layer = DG.Layer.extend({ }, _getHoveredObject: function (coords, mouseTileOffset) { - for (var i = this._currentTileData.length - 1 ; i >= 0; i--) { + for (var i = this._currentTileData.length - 1; i >= 0; i--) { if (DG.PolyUtil.contains(mouseTileOffset, this._currentTileData[i].geometry.coordinates[0])) { return this._currentTileData[i]; } diff --git a/src/DGMeta/src/DGMeta.Origin.js b/src/DGMeta/src/DGMeta.Origin.js index f591b3ee0..29b2e31fa 100644 --- a/src/DGMeta/src/DGMeta.Origin.js +++ b/src/DGMeta/src/DGMeta.Origin.js @@ -35,7 +35,7 @@ DG.Meta.Origin = DG.Class.extend({ if (this._tileStorage[tileKey].constructor === Object) { return Object.keys(this._tileStorage[tileKey]).map(function (id) { - return DG.extend({ geometry: this._tileStorage[tileKey][id]}, this._dataStorage[id]); + return DG.extend({geometry: this._tileStorage[tileKey][id]}, this._dataStorage[id]); }, this); } @@ -66,7 +66,9 @@ DG.Meta.Origin = DG.Class.extend({ this._tileStorage = {}; this._dataStorage = {}; Object.keys(this._requests).forEach(function (tileKey) { - this[tileKey].abort && this[tileKey].abort(); + if (this[tileKey].abort) { + this[tileKey].abort(); + } }, this._requests); return this; diff --git a/src/DGMeta/src/PolyUtilContains.js b/src/DGMeta/src/PolyUtilContains.js index 30dbe3b57..ab0d9e087 100644 --- a/src/DGMeta/src/PolyUtilContains.js +++ b/src/DGMeta/src/PolyUtilContains.js @@ -1,16 +1,16 @@ // ray tracing method: http://algolist.ru/maths/geom/belong/poly2d.php DG.PolyUtil.contains = function (point, geometry) { // (DG.LatLng, Array) -> Boolean - var edges, + var edges, i, len, parity = 0, vertices = []; - for (var i = 0, len = geometry.length; i < len; i++) { + for (i = 0, len = geometry.length; i < len; i++) { vertices.push(DG.point(geometry[i])); } edges = this._getEdges(vertices); - for (var i = 0, len = edges.length; i < len; i++) { // jshint ignore:line + for (i = 0, len = edges.length; i < len; i++) { switch (this._getEdgeType(edges[i], point)) { case 'TOUCHING': return true; diff --git a/src/DGPoi/src/DGPoi.js b/src/DGPoi/src/DGPoi.js index 2f435acce..416cfd682 100644 --- a/src/DGPoi/src/DGPoi.js +++ b/src/DGPoi/src/DGPoi.js @@ -1,4 +1,4 @@ -/*global __POI_LAYER_MIN_ZOOM__:false */ +/* global __POI_LAYER_MIN_ZOOM__,__DETECT_RETINA__ */ DG.Map.mergeOptions({ poi: !DG.Browser.touch diff --git a/src/DGPopup/src/DGPopup.js b/src/DGPopup/src/DGPopup.js index bd7a06bf2..9169c44b0 100644 --- a/src/DGPopup/src/DGPopup.js +++ b/src/DGPopup/src/DGPopup.js @@ -1,13 +1,11 @@ -//2GIS-related popup content wrapper and offset +// 2GIS-related popup content wrapper and offset (function () { var offsetX = DG.configTheme.balloonOptions.offset.x, offsetY = DG.configTheme.balloonOptions.offset.y, originalInitialize = DG.Popup.prototype.initialize, originalInitLayout = DG.Popup.prototype._initLayout, - originalOnClose = DG.Popup.prototype._onCloseButtonClick, originalOnAdd = DG.Popup.prototype.onAdd, originalAdjustPan = DG.Popup.prototype._adjustPan, - /*global baron:false */ graf = baron.noConflict(); var BaronDomHelper = function (element) { @@ -92,7 +90,7 @@ }, setContent: function (content) { // (DOMElement | Object | HTML) -> Popup - if (!this._isNode(content) && typeof content === 'object' && typeof content !== null) { + if (!this._isNode(content) && typeof content === 'object') { Object.keys(content).forEach(function (item) { this['_' + item + 'Content'] = content[item]; }, this); @@ -177,7 +175,9 @@ // See https://github.com/2gis/mapsapi/pull/153/ DG.DomEvent.disableClickPropagation(this._innerContainer); - this.options.closeButton && this._innerContainer.appendChild(this._detachEl(this._closeButton)); + if (this.options.closeButton) { + this._innerContainer.appendChild(this._detachEl(this._closeButton)); + } this._innerContainer.appendChild(this._detachEl(this._wrapper)); @@ -210,13 +210,12 @@ }, _updateScrollPosition: function () { - this._baron && this._baron.update(); + if (this._baron) { + this._baron.update(); + } }, resize: function () { - var content = this._contentNode, - scrolledClass = 'leaflet-popup-scrolled'; - var scrolled = this._updateLayout(); this._updatePosition(); @@ -229,25 +228,23 @@ DG.DomUtil.removeClass(this._scroller, 'dg-scroller'); DG.DomEvent.off(this._scroller, 'scroll', this._onScroll); } - } else { - if (this._isBaronExist) { - DG.DomUtil.removeClass(this._scroller, 'dg-scroller_hidden_true'); - DG.DomUtil.addClass(this._scroller, 'dg-scroller'); + } else if (this._isBaronExist) { + DG.DomUtil.removeClass(this._scroller, 'dg-scroller_hidden_true'); + DG.DomUtil.addClass(this._scroller, 'dg-scroller'); - var scrollTop = this._isBaronExist ? this._scroller.scrollTop : false; + var scrollTop = this._isBaronExist ? this._scroller.scrollTop : false; - if (scrollTop) { - this._scroller.scrollTop = scrollTop; - } + if (scrollTop) { + this._scroller.scrollTop = scrollTop; + } - var innerHeight = this.options.maxHeight - this.options.border * 2 - this._getDelta(); - this._scrollerWrapper.style.height = innerHeight + 'px'; + var innerHeight = this.options.maxHeight - this.options.border * 2 - this._getDelta(); + this._scrollerWrapper.style.height = innerHeight + 'px'; - this._updateScrollPosition(); - } else { - this._initBaronScroller(); - this._initBaron(); - } + this._updateScrollPosition(); + } else { + this._initBaronScroller(); + this._initBaron(); } this._adjustPan(); @@ -319,9 +316,11 @@ }, _bindAdjustPanOnTransitionEnd: function () { - DG.DomUtil.TRANSITION ? - DG.DomEvent.on(this._wrapper, DG.DomUtil.TRANSITION_END, this._adjustPan, this) : + if (DG.DomUtil.TRANSITION) { + DG.DomEvent.on(this._wrapper, DG.DomUtil.TRANSITION_END, this._adjustPan, this); + } else { this._adjustPan(); + } }, _isContentHeightEnough: function () { // () -> Boolean @@ -452,10 +451,10 @@ this._clearNode(this._contentNode); this._isBaronExist = false; - //init popup content dom structure - this._headerContent && this._initHeader(); - this._bodyContent && this._initBodyContainer(); - this._footerContent && this._initFooter(); + // init popup content dom structure + if (this._headerContent) { this._initHeader(); } + if (this._bodyContent) { this._initBodyContainer(); } + if (this._footerContent) { this._initFooter(); } this._updatePopupStructure(); this.resize(); @@ -562,7 +561,9 @@ }, _detachEl: function (elem) { // (DOMElement) -> DOMElement - elem.parentNode && elem.parentNode.removeChild(elem); + if (elem.parentNode) { + elem.parentNode.removeChild(elem); + } return elem; }, @@ -574,7 +575,10 @@ } else { DG.DomEvent[switcher](this._contentNode, 'touchstart mousedown mousemove', this._onStart, this); } - this._isBaronExist && DG.DomEvent[switcher](this._scroller, 'scroll', this._onScroll, this); + + if (this._isBaronExist) { + DG.DomEvent[switcher](this._scroller, 'scroll', this._onScroll, this); + } }, _toggleTouchEvents: function (on) { diff --git a/src/DGProjectDetector/src/DGProjectDetector.js b/src/DGProjectDetector/src/DGProjectDetector.js index 69ca17b28..a030b025a 100644 --- a/src/DGProjectDetector/src/DGProjectDetector.js +++ b/src/DGProjectDetector/src/DGProjectDetector.js @@ -25,7 +25,7 @@ DG.ProjectDetector = DG.Handler.extend({ }, isProjectHere: function (coords, project, checkMethod) { - if (!coords) { return; } + if (!coords) { return null; } if (!(coords instanceof DG.LatLng) && !(coords instanceof DG.LatLngBounds)) { coords = DG.latLng(coords); @@ -36,11 +36,11 @@ DG.ProjectDetector = DG.Handler.extend({ checkMethod = checkMethod || ((coords instanceof DG.LatLngBounds) ? 'intersects' : 'contains'); - return project ? - this._testProject(checkMethod, coords, project) : - this._projectList.filter( - this._testProject.bind(this, checkMethod, coords) - )[0]; + if (project) { + return this._testProject(checkMethod, coords, project); + } else { + return this._projectList.filter(this._testProject.bind(this, checkMethod, coords))[0]; + } }, _projectWatch: function () { @@ -104,9 +104,9 @@ DG.ProjectDetector = DG.Handler.extend({ var bound = self._wktToBnd(project.bounds); var latLngBounds = new DG.LatLngBounds(bound); + /* eslint-disable camelcase */ return { code: project.code, - /*jshint camelcase: false */ minZoom: project.zoom_level.min, maxZoom: project.zoom_level.max, timeOffset: project.time_zone.offset, @@ -118,6 +118,7 @@ DG.ProjectDetector = DG.Handler.extend({ country_code: project.country_code, domain: project.domain }; + /* eslint-enable camelcase */ }); }, diff --git a/src/DGRuler/src/Ruler.js b/src/DGRuler/src/Ruler.js index 7c3899121..f6fdbab0c 100644 --- a/src/DGRuler/src/Ruler.js +++ b/src/DGRuler/src/Ruler.js @@ -77,7 +77,7 @@ DG.Ruler = DG.Layer.extend({ return this._calcDistance(); }, - spliceLatLngs: function (index, pointsToRemove) { // (Number, Number, args ...) -> Array + spliceLatLngs: function (index) { // (Number, Number, args ...) -> Array var oldLength = this._points.length, mutationStart = index >= 0 ? Math.min(index, oldLength) : oldLength - index, removed = Array.prototype.splice.apply(this._points, arguments).map(function (point) { @@ -224,7 +224,7 @@ DG.Ruler = DG.Layer.extend({ }, _fireChangeEvent: function () { - this.fire('changed', { latlngs : this.getLatLngs() }); + this.fire('changed', {latlngs : this.getLatLngs()}); }, _addRunningLabel: function (latlng, previousPoint) { // (LatLng, Ruler.LayeredMarker) @@ -383,7 +383,7 @@ DG.Ruler = DG.Layer.extend({ // Update legs of all points that changed position changedPoints.sort().reduce(function (previous, current) { - var skipPrevious = previous && previous == current - 1; + var skipPrevious = previous && previous === current - 1; self._updateLegs(self._points[current], skipPrevious); @@ -393,9 +393,7 @@ DG.Ruler = DG.Layer.extend({ _pointEvents: { drag: function (event) { // (Event) - var point = event.target, - latlng = point.getLatLng(), - lastPoint = this._points[point._pos - 1] || null; + var point = event.target; this._normalizeRulerPoints(point); @@ -586,8 +584,6 @@ DG.Ruler = DG.Layer.extend({ }, _addLegs: function (point) { - var self = this; - var pathStyles = this.options.pathStyles; var greatCirclePoints = this._calcGreatCircle( @@ -659,7 +655,7 @@ DG.Ruler = DG.Layer.extend({ return distance; }, - _getFormatedDistance: function (finishPoint, tail) { // (Ruler.LayeredMarker, Number) -> String + _getFormatedDistance: function () { // () -> String var distance = this._calcDistance.apply(this, arguments), units = 'm'; diff --git a/src/DGRulerControl/src/Control.Ruler.js b/src/DGRulerControl/src/Control.Ruler.js index 9bca84106..3c09f150e 100644 --- a/src/DGRulerControl/src/Control.Ruler.js +++ b/src/DGRulerControl/src/Control.Ruler.js @@ -23,7 +23,9 @@ DG.Control.Ruler = DG.RoundControl.extend({ this._drawingHelper = DG.ruler([]); }, click: function () { - if (this._active = !this._active) { // jshint ignore:line + this._active = !this._active; + + if (this._active) { this.setState('active'); this._startDrawing(); } else { @@ -59,7 +61,7 @@ DG.Control.Ruler = DG.RoundControl.extend({ this._map.fire('rulerend'); }, - _handleMapClick: function (event) { // (MouseEvents) + _handleMapClick: function (event) { // (MouseEvents) this._drawingHelper.addLatLng(event.latlng); }, diff --git a/src/DGTraffic/src/DGTraffic.js b/src/DGTraffic/src/DGTraffic.js index f83d63fbb..2ffdfe024 100644 --- a/src/DGTraffic/src/DGTraffic.js +++ b/src/DGTraffic/src/DGTraffic.js @@ -1,4 +1,4 @@ -/* global __TRAFFIC_LAYER_UPDATE_INTERVAL__, __TRAFFIC_LAYER_MIN_ZOOM__ */ +/* global __TRAFFIC_LAYER_UPDATE_INTERVAL__, __TRAFFIC_LAYER_MIN_ZOOM__,__DETECT_RETINA__ */ DG.Traffic = DG.TileLayer.extend({ @@ -83,7 +83,7 @@ DG.Traffic = DG.TileLayer.extend({ self.options.timestampString = '?' + (new Date()).getTime(); }).then( function () { - self.fire('update', { timestamp: self.options.timestampString }); + self.fire('update', {timestamp: self.options.timestampString}); self._layerEventsListeners.mouseout.call(self); self._metaLayer.getOrigin().setURL(self._prepareMetaURL(), self); self.redraw(); @@ -92,12 +92,21 @@ DG.Traffic = DG.TileLayer.extend({ }, getSubdomain: function () { - return DG.Traffic.layersOptions.subdomains[Math.floor(Math.random() * DG.Traffic.layersOptions.subdomains.length)]; + return DG.Traffic.layersOptions.subdomains[ + Math.floor(Math.random() * DG.Traffic.layersOptions.subdomains.length) + ]; }, _getTimestampString: function () { - return DG.ajax(DG.Util.template(DG.Traffic.timeUrl, DG.extend({ s : this.getSubdomain(), projectCode: this._map.projectDetector.getProject().code}, this.options || {})), - { type: 'get' }); + return DG.ajax( + DG.Util.template( + DG.Traffic.timeUrl, + DG.extend({ + s : this.getSubdomain(), + projectCode: this._map.projectDetector.getProject().code + }, this.options || {})), + {type: 'get'} + ); }, _onTimer: function () { diff --git a/src/DGTrafficControl/src/Control.Traffic.js b/src/DGTrafficControl/src/Control.Traffic.js index a92393aa2..fed1818e6 100644 --- a/src/DGTrafficControl/src/Control.Traffic.js +++ b/src/DGTrafficControl/src/Control.Traffic.js @@ -30,7 +30,9 @@ DG.Control.Traffic = DG.RoundControl.extend({ this._map.on('zoomend projectchange projectleave', this._updateControlVisibility, this); }, click: function () { - if (this._active = !this._active) { // jshint ignore:line + this._active = !this._active; + + if (this._active) { this.setState('active'); this._showTraffic(); } else { @@ -111,7 +113,7 @@ DG.Control.Traffic = DG.RoundControl.extend({ } ); - return DG.ajax(url, {type: 'get' }); + return DG.ajax(url, {type: 'get'}); }, _renderTranslation: function () { // () diff --git a/src/DGWkt/DGWkt.js b/src/DGWkt/DGWkt.js index a44e7efc1..9b60a35af 100644 --- a/src/DGWkt/DGWkt.js +++ b/src/DGWkt/DGWkt.js @@ -1,4 +1,3 @@ -/* jshint ignore:start */ DG.Wkt = {}; DG.Wkt.toGeoJSON = function (_) { @@ -221,4 +220,3 @@ DG.Wkt.pointsToLatLngOnMap = function (wkt, map) { map.containerPointToLatLng(points); })(DG.Wkt.toPoints(wkt)); }; -/* jshint ignore:end */ \ No newline at end of file diff --git a/src/DGZoomControl/src/DGZoomControl.js b/src/DGZoomControl/src/DGZoomControl.js index 4f1cc2476..9417b1bc8 100644 --- a/src/DGZoomControl/src/DGZoomControl.js +++ b/src/DGZoomControl/src/DGZoomControl.js @@ -10,8 +10,8 @@ DG.Control.Zoom.include({ this._map = map; - this._zoomInButton = this._createButton(DG.Util.template(buttonTemplate, { type : 'in' }), this.t('zoom_in'), 'dg-control-round ' + zoomName + '__in', container, this._zoomIn, this); - this._zoomOutButton = this._createButton(DG.Util.template(buttonTemplate, { type : 'out' }), this.t('zoom_out'), 'dg-control-round ' + zoomName + '__out', container, this._zoomOut, this); + this._zoomInButton = this._createButton(DG.Util.template(buttonTemplate, {type : 'in'}), this.t('zoom_in'), 'dg-control-round ' + zoomName + '__in', container, this._zoomIn, this); + this._zoomOutButton = this._createButton(DG.Util.template(buttonTemplate, {type : 'out'}), this.t('zoom_out'), 'dg-control-round ' + zoomName + '__out', container, this._zoomOut, this); this._eventListeners = {}; this._eventListeners.zoomend = this._eventListeners.zoomlevelschange = this._updateDisabled; @@ -23,7 +23,7 @@ DG.Control.Zoom.include({ _originalCreateButton: DG.Control.Zoom.prototype._createButton, - _createButton: function (html, title, className, container, fn) { + _createButton: function () { var args = Array.prototype.slice.call(arguments); var link = this._originalCreateButton.apply(this, args);