add ESLint rules; various code style fixes

This commit is contained in:
Vladimir Agafonkin 2015-01-28 17:27:31 +02:00
parent 65efd30567
commit e749d1915b
14 changed files with 61 additions and 30 deletions

View File

@ -3,20 +3,21 @@
"version": "0.8.0-dev",
"description": "JavaScript library for mobile-friendly interactive maps",
"devDependencies": {
"jake": "~8.0.10",
"jshint": "~2.5.7",
"uglify-js": "~2.4.15",
"mocha": "~2.0.1",
"copyfiles": "0.1.0",
"eslint": "^0.13.0",
"happen": "~0.1.3",
"karma": "~0.12.24",
"karma-mocha": "~0.1.9",
"karma-coverage": "~0.2.6",
"jake": "~8.0.10",
"jshint": "~2.6.0",
"karma": "~0.12.31",
"karma-chrome-launcher": "^0.1.7",
"karma-coverage": "~0.2.7",
"karma-firefox-launcher": "~0.1.4",
"karma-mocha": "~0.1.10",
"karma-phantomjs-launcher": "^0.1.4",
"karma-chrome-launcher": "^0.1.5",
"karma-firefox-launcher": "~0.1.3",
"karma-safari-launcher": "~0.1.1",
"mocha": "~2.1.0",
"tin": "^0.5.0",
"copyfiles": "0.1.0"
"uglify-js": "~2.4.16"
},
"main": "dist/leaflet-src.js",
"style": "dist/leaflet.css",
@ -38,5 +39,33 @@
"type": "BSD-2-Clause",
"url": "https://github.com/Leaflet/Leaflet/blob/master/LICENSE"
}
]
],
"eslintConfig": {
"rules": {
"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,
"no-underscore-dangle": 0,
"no-constant-condition": 0,
"no-multi-spaces": 0,
"strict": 0,
"key-spacing": 0,
"no-shadow": 0
},
"globals": {
"L": true,
"module": false,
"define": false
},
"env": {
"browser": true
}
}
}

View File

@ -100,4 +100,3 @@ L.Map.addInitHook(function () {
L.control.zoom = function (options) {
return new L.Control.Zoom(options);
};

View File

@ -42,9 +42,10 @@ L.Util = {
// return unique ID of an object
stamp: function (obj) {
// jshint camelcase: false
/*eslint-disable */
obj._leaflet_id = obj._leaflet_id || ++L.Util.lastId;
return obj._leaflet_id;
/*eslint-enable */
},
lastId: 0,

View File

@ -54,7 +54,7 @@ L.DomEvent = {
if (L.Browser.pointer && type.indexOf('touch') === 0) {
this.addPointerListener(obj, type, handler, id);
} else if (L.Browser.touch && (type === 'dblclick') && this.addDoubleTapListener) {
this.addDoubleTapListener(obj, handler, id);
@ -67,8 +67,9 @@ L.DomEvent = {
} else if ((type === 'mouseenter') || (type === 'mouseleave')) {
handler = function (e) {
e = e || window.event;
if (!L.DomEvent._checkMouse(obj, e)) { return; }
return originalHandler(e);
if (L.DomEvent._checkMouse(obj, e)) {
originalHandler(e);
}
};
obj.addEventListener(type === 'mouseenter' ? 'mouseover' : 'mouseout', handler, false);
@ -240,7 +241,7 @@ L.DomEvent = {
}
L.DomEvent._lastClick = timeStamp;
return handler(e);
handler(e);
}
};

View File

@ -145,8 +145,9 @@ L.DomUtil = {
setPosition: function (el, point, no3d) { // (HTMLElement, Point[, Boolean])
// jshint camelcase: false
/*eslint-disable */
el._leaflet_pos = point;
/*eslint-enable */
if (L.Browser.any3d && !no3d) {
L.DomUtil.setTransform(el, point);

View File

@ -80,4 +80,3 @@ L.latLng = function (a, b, c) {
}
return new L.LatLng(a, b, c);
};

View File

@ -10,7 +10,7 @@ L.LineUtil = {
// Simplify polyline with vertex reduction and Douglas-Peucker simplification.
// Improves rendering performance dramatically by lessening the number of points to draw.
simplify: function (/*Point[]*/ points, /*Number*/ tolerance) {
simplify: function (points, tolerance) {
if (!tolerance || !points.length) {
return points.slice();
}
@ -27,11 +27,11 @@ L.LineUtil = {
},
// distance from a point to a segment between two points
pointToSegmentDistance: function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2) {
pointToSegmentDistance: function (p, p1, p2) {
return Math.sqrt(this._sqClosestPointOnSegment(p, p1, p2, true));
},
closestPointOnSegment: function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2) {
closestPointOnSegment: function (p, p1, p2) {
return this._sqClosestPointOnSegment(p, p1, p2);
},

View File

@ -2,7 +2,7 @@
* L.Point represents a point with x and y coordinates.
*/
L.Point = function (/*Number*/ x, /*Number*/ y, /*Boolean*/ round) {
L.Point = function (x, y, round) {
this.x = (round ? Math.round(x) : x);
this.y = (round ? Math.round(y) : y);
};

View File

@ -132,7 +132,7 @@ L.Popup = L.Layer.extend({
}
return events;
},
isOpen: function () {
return !!this._map && this._map.hasLayer(this);
},

View File

@ -58,7 +58,7 @@ L.Marker = L.Layer.extend({
var oldLatLng = this._latlng;
this._latlng = L.latLng(latlng);
this.update();
return this.fire('move', { oldLatLng: oldLatLng, latlng: this._latlng });
return this.fire('move', {oldLatLng: oldLatLng, latlng: this._latlng});
},
setZIndexOffset: function (offset) {

View File

@ -220,7 +220,8 @@ L.GridLayer = L.Layer.extend({
tile.retain = true;
if (!tile.loaded) {
found = this._retainParent(i, j, z, z - 5) || this._retainChildren(i, j, z, z + 2);
found = this._retainParent(i, j, z, z - 5);
if (!found) { this._retainChildren(i, j, z, z + 2); }
}
}
}

View File

@ -122,7 +122,7 @@ L.SVG = L.Renderer.extend({
// drawing a circle with two half-arcs
var d = layer._empty() ? 'M0 0' :
'M' + (p.x - r) + ',' + p.y +
arc + (r * 2) + ',0 ' +
arc + (r * 2) + ',0 ' +
arc + (-r * 2) + ',0 ';
this._setPath(layer, d);

View File

@ -83,7 +83,7 @@ L.Map.BoxZoom = L.Handler.extend({
},
_onMouseUp: function (e) {
if ((e.which !== 1) && (e.button !== 1)) { return false; }
if ((e.which !== 1) && (e.button !== 1)) { return; }
this._finish();

View File

@ -48,7 +48,7 @@ L.Map.Tap = L.Handler.extend({
this._simulateEvent('contextmenu', first);
}
}, this), 1000);
this._simulateEvent('mousedown', first);
L.DomEvent.on(document, {
@ -73,7 +73,7 @@ L.Map.Tap = L.Handler.extend({
if (el && el.tagName && el.tagName.toLowerCase() === 'a') {
L.DomUtil.removeClass(el, 'leaflet-active');
}
this._simulateEvent('mouseup', first);
// simulate click if the touch didn't move too much