diff --git a/.eslintrc b/.eslintrc index 4dc01117..35c4f288 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,42 +1,18 @@ { - "rules": { - "eqeqeq": 2, - "consistent-return": 2, - "no-loop-func": 2, - "no-use-before-define": [2, "nofunc"], - "no-lonely-if": 2, - "no-else-return": 2, - "no-new": 2, - "no-throw-literal": 2, - "no-self-compare": 2, - "no-void": 2, - "no-eq-null": 2, - - "quotes": [2, "single"], - "camelcase": 2, - "comma-style": 2, - "comma-spacing": 2, - "new-cap": 2, - "no-empty": 2, - "brace-style": [2, "1tbs", {"allowSingleLine": true}], - "space-in-parens": 2, - "space-before-blocks": 2, - "space-after-keywords": 2, - "space-infix-ops": 2, - "space-unary-ops": 2, - "space-before-function-paren": [2, {"anonymous": "always", "named": "never"}], - "array-bracket-spacing": 2, - "no-mixed-spaces-and-tabs": [2, "smart-tabs"], - - "no-constant-condition": 0 - }, "globals": { "L": true, - "module": false, - "define": false }, "env": { - "browser": true + "commonjs": true, + "amd": true, + "node": false }, - "extends": "eslint:recommended" + "extends": "mourner", + "rules": { + "no-mixed-spaces-and-tabs": [2, "smart-tabs"], + "indent": [2, "tab", {"VariableDeclarator": 0}], + "strict": 0, + "wrap-iife": 0, + "key-spacing": 0 + } } diff --git a/package.json b/package.json index 839124a1..fe03a47a 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "JavaScript library for mobile-friendly interactive maps", "devDependencies": { "copyfiles": "0.2.1", - "eslint": "^1.3.1", + "eslint": "^1.5.1", + "eslint-config-mourner": "^1.0.0", "happen": "~0.2.0", "jake": "~8.0.12", "karma": "~0.13.9", diff --git a/spec/.eslintrc b/spec/.eslintrc index ff48b0da..a11c9278 100644 --- a/spec/.eslintrc +++ b/spec/.eslintrc @@ -4,21 +4,15 @@ "quotes": 0, "no-shadow": 0, "no-irregular-whitespace": 0, - "no-console": 0 - }, - "globals": { - "L": true, - "module": false, - "define": false, - "expect": false, - "it": false, - "describe": false, - "sinon": false, - "happen": false, - "beforeEach": false, - "afterEach": false + "no-console": 0, + "indent": 0 }, "env": { - "browser": true + "mocha": true + }, + "globals": { + "expect": false, + "sinon": false, + "happen": false } } diff --git a/spec/suites/geo/CRSSpec.js b/spec/suites/geo/CRSSpec.js index 32b18289..837e936f 100644 --- a/spec/suites/geo/CRSSpec.js +++ b/spec/suites/geo/CRSSpec.js @@ -160,7 +160,7 @@ describe("CRS.Simple", function () { describe("CRS", function () { var crs = L.CRS; - + describe("#zoom && #scale", function () { it("convert zoom to scale and viceversa and return the same values", function () { var zoom = 2.5; @@ -188,7 +188,7 @@ describe("CRS.ZoomNotPowerOfTwo", function () { expect(crs.zoom(1.5 * scale)).to.eql(zoom + 1); }); }); - + describe("#zoom && #scale", function () { it("convert zoom to scale and viceversa and return the same values", function () { var zoom = 2; @@ -196,4 +196,4 @@ describe("CRS.ZoomNotPowerOfTwo", function () { expect(crs.zoom(scale)).to.eql(zoom); }); }); -}); \ No newline at end of file +}); diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index d0302ce8..6482c25a 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -746,7 +746,7 @@ describe("Map", function () { }); }); - + describe('#getScaleZoom && #getZoomScale', function () { it("convert zoom to scale and viceversa and return the same values", function () { var toZoom = 6.25; diff --git a/src/control/Control.Layers.js b/src/control/Control.Layers.js index 88556c2b..b107c51b 100644 --- a/src/control/Control.Layers.js +++ b/src/control/Control.Layers.js @@ -262,7 +262,7 @@ L.Control.Layers = L.Control.extend({ L.DomUtil.addClass(this._form, 'leaflet-control-layers-scrollbar'); this._form.style.height = acceptableHeight + 'px'; } else { - L.DomUtil.removeClass(this._form, 'leaflet-control-layers-scrollbar'); + L.DomUtil.removeClass(this._form, 'leaflet-control-layers-scrollbar'); } this._checkDisabledLayers(); }, diff --git a/src/control/Control.Zoom.js b/src/control/Control.Zoom.js index 978d2579..629f81db 100644 --- a/src/control/Control.Zoom.js +++ b/src/control/Control.Zoom.js @@ -72,7 +72,7 @@ L.Control.Zoom = L.Control.extend({ _updateDisabled: function () { var map = this._map, - className = 'leaflet-disabled'; + className = 'leaflet-disabled'; L.DomUtil.removeClass(this._zoomInButton, className); L.DomUtil.removeClass(this._zoomOutButton, className); diff --git a/src/dom/DomEvent.DoubleTap.js b/src/dom/DomEvent.DoubleTap.js index dcc66969..d3ec09ec 100644 --- a/src/dom/DomEvent.DoubleTap.js +++ b/src/dom/DomEvent.DoubleTap.js @@ -37,7 +37,7 @@ L.extend(L.DomEvent, { if (L.Browser.pointer) { // work around .type being readonly with MSPointer* events var newTouch = {}, - prop, i; + prop, i; for (i in touch) { prop = touch[i]; diff --git a/src/dom/DomEvent.js b/src/dom/DomEvent.js index 2a87a5e6..c23d2757 100644 --- a/src/dom/DomEvent.js +++ b/src/dom/DomEvent.js @@ -230,7 +230,7 @@ L.DomEvent = { // this is a horrible workaround for a bug in Android where a single touch triggers two click events _filterClick: function (e, handler) { var timeStamp = (e.timeStamp || e.originalEvent.timeStamp), - elapsed = L.DomEvent._lastClick && (timeStamp - L.DomEvent._lastClick); + elapsed = L.DomEvent._lastClick && (timeStamp - L.DomEvent._lastClick); // are they closer together than 500ms yet more than 100ms? // Android typically triggers them ~300ms apart while multiple listeners diff --git a/src/dom/DomUtil.js b/src/dom/DomUtil.js index 607af9f0..19896602 100644 --- a/src/dom/DomUtil.js +++ b/src/dom/DomUtil.js @@ -143,7 +143,10 @@ L.DomUtil = { var pos = offset || new L.Point(0, 0); el.style[L.DomUtil.TRANSFORM] = - (L.Browser.ie3d ? 'translate(' + pos.x + 'px,' + pos.y + 'px' + ')' : 'translate3d(' + pos.x + 'px,' + pos.y + 'px' + ',0)') + (scale ? ' scale(' + scale + ')' : ''); + (L.Browser.ie3d ? + 'translate(' + pos.x + 'px,' + pos.y + 'px)' : + 'translate3d(' + pos.x + 'px,' + pos.y + 'px,0)') + + (scale ? ' scale(' + scale + ')' : ''); }, setPosition: function (el, point) { // (HTMLElement, Point[, Boolean]) diff --git a/src/geo/LatLng.js b/src/geo/LatLng.js index 83a44568..8bfdf256 100644 --- a/src/geo/LatLng.js +++ b/src/geo/LatLng.js @@ -44,7 +44,7 @@ L.LatLng.prototype = { toBounds: function (sizeInMeters) { var latAccuracy = 180 * sizeInMeters / 40075017, - lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * this.lat); + lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * this.lat); return L.latLngBounds( [this.lat - latAccuracy, this.lng - lngAccuracy], diff --git a/src/geo/LatLngBounds.js b/src/geo/LatLngBounds.js index af046d01..8b52c843 100644 --- a/src/geo/LatLngBounds.js +++ b/src/geo/LatLngBounds.js @@ -17,8 +17,8 @@ L.LatLngBounds.prototype = { // extend the bounds to contain the given point or bounds extend: function (obj) { // (LatLng) or (LatLngBounds) var sw = this._southWest, - ne = this._northEast, - sw2, ne2; + ne = this._northEast, + sw2, ne2; if (obj instanceof L.LatLng) { sw2 = obj; diff --git a/src/geo/crs/CRS.js b/src/geo/crs/CRS.js index 4a00f049..a82e8f05 100644 --- a/src/geo/crs/CRS.js +++ b/src/geo/crs/CRS.js @@ -33,7 +33,7 @@ L.CRS = { scale: function (zoom) { return 256 * Math.pow(2, zoom); }, - + zoom: function (scale) { return Math.log(scale / 256) / Math.LN2; }, diff --git a/src/layer/GeoJSON.js b/src/layer/GeoJSON.js index cbee4d39..3951338a 100644 --- a/src/layer/GeoJSON.js +++ b/src/layer/GeoJSON.js @@ -250,7 +250,7 @@ L.LayerGroup.include({ } var isGeometryCollection = type === 'GeometryCollection', - jsons = []; + jsons = []; this.eachLayer(function (layer) { if (layer.toGeoJSON) { diff --git a/src/layer/ImageOverlay.js b/src/layer/ImageOverlay.js index 246fd943..09984df9 100644 --- a/src/layer/ImageOverlay.js +++ b/src/layer/ImageOverlay.js @@ -138,7 +138,7 @@ L.ImageOverlay = L.Layer.extend({ _animateZoom: function (e) { var scale = this._map.getZoomScale(e.zoom), - offset = this._map._latLngToNewLayerPoint(this._bounds.getNorthWest(), e.zoom, e.center); + offset = this._map._latLngToNewLayerPoint(this._bounds.getNorthWest(), e.zoom, e.center); L.DomUtil.setTransform(this._image, offset, scale); }, diff --git a/src/layer/Layer.js b/src/layer/Layer.js index 5bdcea6c..a1c2a527 100644 --- a/src/layer/Layer.js +++ b/src/layer/Layer.js @@ -144,8 +144,8 @@ L.Map.include({ _updateZoomLevels: function () { var minZoom = Infinity, - maxZoom = -Infinity, - oldZoomSpan = this._getZoomSpan(); + maxZoom = -Infinity, + oldZoomSpan = this._getZoomSpan(); for (var i in this._zoomBoundLayers) { var options = this._zoomBoundLayers[i].options; diff --git a/src/layer/marker/Marker.js b/src/layer/marker/Marker.js index c758ba2d..836c36be 100644 --- a/src/layer/marker/Marker.js +++ b/src/layer/marker/Marker.js @@ -106,7 +106,7 @@ L.Marker = L.Layer.extend({ classToAdd = 'leaflet-zoom-' + (this._zoomAnimated ? 'animated' : 'hide'); var icon = options.icon.createIcon(this._icon), - addIcon = false; + addIcon = false; // if we're not reusing the icon, remove the old one and init new one if (icon !== this._icon) { @@ -139,7 +139,7 @@ L.Marker = L.Layer.extend({ } var newShadow = options.icon.createShadow(this._shadow), - addShadow = false; + addShadow = false; if (newShadow !== this._shadow) { this._removeShadow(); @@ -170,7 +170,7 @@ L.Marker = L.Layer.extend({ if (this.options.riseOnHover) { this.off({ mouseover: this._bringToFront, - mouseout: this._resetZIndex + mouseout: this._resetZIndex }); } diff --git a/src/layer/tile/GridLayer.js b/src/layer/tile/GridLayer.js index bba4ca7a..4ec44cbc 100644 --- a/src/layer/tile/GridLayer.js +++ b/src/layer/tile/GridLayer.js @@ -165,8 +165,8 @@ L.GridLayer = L.Layer.extend({ L.DomUtil.setOpacity(this._container, this.options.opacity); var now = +new Date(), - nextFrame = false, - willPrune = false; + nextFrame = false, + willPrune = false; for (var key in this._tiles) { var tile = this._tiles[key]; @@ -207,7 +207,7 @@ L.GridLayer = L.Layer.extend({ _updateLevels: function () { var zoom = this._tileZoom, - maxZoom = this.options.maxZoom; + maxZoom = this.options.maxZoom; for (var z in this._levels) { if (this._levels[z].el.children.length || z === zoom) { @@ -289,11 +289,11 @@ L.GridLayer = L.Layer.extend({ _retainParent: function (x, y, z, minZoom) { var x2 = Math.floor(x / 2), - y2 = Math.floor(y / 2), - z2 = z - 1; + y2 = Math.floor(y / 2), + z2 = z - 1; var key = x2 + ':' + y2 + ':' + z2, - tile = this._tiles[key]; + tile = this._tiles[key]; if (tile && tile.active) { tile.retain = true; @@ -316,7 +316,7 @@ L.GridLayer = L.Layer.extend({ for (var j = 2 * y; j < 2 * y + 2; j++) { var key = i + ':' + j + ':' + (z + 1), - tile = this._tiles[key]; + tile = this._tiles[key]; if (tile && tile.active) { tile.retain = true; @@ -424,11 +424,10 @@ L.GridLayer = L.Layer.extend({ }, _getTiledPixelBounds: function (center, zoom, tileZoom) { - var map = this._map; - - var scale = map.getZoomScale(zoom, tileZoom), - pixelCenter = map.project(center, tileZoom).floor(), - halfSize = map.getSize().divideBy(scale * 2); + var map = this._map, + scale = map.getZoomScale(zoom, tileZoom), + pixelCenter = map.project(center, tileZoom).floor(), + halfSize = map.getSize().divideBy(scale * 2); return new L.Bounds(pixelCenter.subtract(halfSize), pixelCenter.add(halfSize)); }, @@ -442,11 +441,10 @@ L.GridLayer = L.Layer.extend({ if (center === undefined) { center = map.getCenter(); } if (this._tileZoom === undefined) { return; } // if out of minzoom/maxzoom - var pixelBounds = this._getTiledPixelBounds(center, zoom, this._tileZoom); - - var tileRange = this._pxBoundsToTileRange(pixelBounds), - tileCenter = tileRange.getCenter(), - queue = []; + var pixelBounds = this._getTiledPixelBounds(center, zoom, this._tileZoom), + tileRange = this._pxBoundsToTileRange(pixelBounds), + tileCenter = tileRange.getCenter(), + queue = []; for (var key in this._tiles) { this._tiles[key].current = false; @@ -540,7 +538,7 @@ L.GridLayer = L.Layer.extend({ // converts tile cache key to coordinates _keyToTileCoords: function (key) { var k = key.split(':'), - coords = new L.Point(+k[0], +k[1]); + coords = new L.Point(+k[0], +k[1]); coords.z = +k[2]; return coords; }, diff --git a/src/layer/vector/Canvas.js b/src/layer/vector/Canvas.js index bfce28e7..ec080d28 100644 --- a/src/layer/vector/Canvas.js +++ b/src/layer/vector/Canvas.js @@ -82,7 +82,7 @@ L.Canvas = L.Renderer.extend({ var padding = (layer.options.weight || 0) + 1; this._redrawBounds = this._redrawBounds || new L.Bounds(); - this._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding])) + this._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding])); this._redrawBounds.extend(layer._pxBounds.max.add([padding, padding])); this._redrawRequest = this._redrawRequest || L.Util.requestAnimFrame(this._redraw, this); diff --git a/src/layer/vector/Polyline.js b/src/layer/vector/Polyline.js index 7a0e387a..14afad2f 100644 --- a/src/layer/vector/Polyline.js +++ b/src/layer/vector/Polyline.js @@ -134,7 +134,7 @@ L.Polyline = L.Path.extend({ // project bounds as well to use later for Canvas hit detection/etc. var w = this._clickTolerance(), - p = new L.Point(w, -w); + p = new L.Point(w, -w); if (this._bounds.isValid()) { this._pxBounds = new L.Bounds( @@ -203,7 +203,7 @@ L.Polyline = L.Path.extend({ // simplify each clipped part of the polyline for performance _simplifyPoints: function () { var parts = this._parts, - tolerance = this.options.smoothFactor; + tolerance = this.options.smoothFactor; for (var i = 0, len = parts.length; i < len; i++) { parts[i] = L.LineUtil.simplify(parts[i], tolerance); diff --git a/src/layer/vector/SVG.js b/src/layer/vector/SVG.js index 0d69e551..eea40c78 100644 --- a/src/layer/vector/SVG.js +++ b/src/layer/vector/SVG.js @@ -68,7 +68,7 @@ L.SVG = L.Renderer.extend({ _updateStyle: function (layer) { var path = layer._path, - options = layer.options; + options = layer.options; if (!path) { return; } @@ -147,7 +147,7 @@ L.extend(L.SVG, { // generates SVG path string for multiple rings, with each ring turning into "M..L..L.." instructions pointsToPath: function (rings, closed) { var str = '', - i, j, len, len2, points, p; + i, j, len, len2, points, p; for (i = 0, len = rings.length; i < len; i++) { points = rings[i]; diff --git a/src/map/Map.js b/src/map/Map.js index 5139f0c7..a578d8c1 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -177,7 +177,7 @@ L.Map = L.Evented.extend({ panInsideBounds: function (bounds, options) { var center = this.getCenter(), - newCenter = this._limitCenter(center, this._zoom, L.latLngBounds(bounds)); + newCenter = this._limitCenter(center, this._zoom, L.latLngBounds(bounds)); if (center.equals(newCenter)) { return this; } @@ -709,8 +709,8 @@ L.Map = L.Evented.extend({ for (var i = 0; i < targets.length; i++) { targets[i].fire(type, data, true); - if (data.originalEvent._stopped - || (targets[i].options.nonBubblingEvents && L.Util.indexOf(targets[i].options.nonBubblingEvents, type) !== -1)) { return; } + if (data.originalEvent._stopped || + (targets[i].options.nonBubblingEvents && L.Util.indexOf(targets[i].options.nonBubblingEvents, type) !== -1)) { return; } } }, diff --git a/src/map/anim/Map.ZoomAnimation.js b/src/map/anim/Map.ZoomAnimation.js index b9285d0d..8724658d 100644 --- a/src/map/anim/Map.ZoomAnimation.js +++ b/src/map/anim/Map.ZoomAnimation.js @@ -35,7 +35,7 @@ L.Map.include(!zoomAnimated ? {} : { this.on('zoomanim', function (e) { var prop = L.DomUtil.TRANSFORM, - transform = proxy.style[prop]; + transform = proxy.style[prop]; L.DomUtil.setTransform(proxy, this.project(e.center, e.zoom), this.getZoomScale(e.zoom, 1)); @@ -47,7 +47,7 @@ L.Map.include(!zoomAnimated ? {} : { this.on('load moveend', function () { var c = this.getCenter(), - z = this.getZoom(); + z = this.getZoom(); L.DomUtil.setTransform(proxy, this.project(c, z), this.getZoomScale(z, 1)); }, this); }, diff --git a/src/map/ext/Map.Geolocation.js b/src/map/ext/Map.Geolocation.js index c1fcf98a..02a60420 100644 --- a/src/map/ext/Map.Geolocation.js +++ b/src/map/ext/Map.Geolocation.js @@ -25,7 +25,7 @@ L.Map.include({ } var onResponse = L.bind(this._handleGeolocationResponse, this), - onError = L.bind(this._handleGeolocationError, this); + onError = L.bind(this._handleGeolocationError, this); if (options.watch) { this._locationWatchId =