From e6ed96223843c124ce59c8037f235df717bae709 Mon Sep 17 00:00:00 2001 From: AoDev Date: Tue, 14 Feb 2017 20:14:13 +0100 Subject: [PATCH] chore(lint): added support for eslint (#2695) --- .eslintrc | 24 ++++++++++++++++++++++-- .travis.yml | 1 + lib/graph3d/Graph3d.js | 10 ++++------ lib/network/modules/LayoutEngine.js | 1 - lib/timeline/DateUtil.js | 1 - lib/timeline/component/ItemSet.js | 4 ++-- lib/timeline/component/item/Item.js | 4 ++-- package.json | 3 +++ 8 files changed, 34 insertions(+), 14 deletions(-) diff --git a/.eslintrc b/.eslintrc index 00d60a6e..1466a3db 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,26 @@ { + "env": { + "browser": true, + "es6": true, + "node": true, + "mocha": true + }, + + "parser": "babel-eslint", + + "extends": "eslint:recommended", + "rules": { - "complexity": [2, 50], - "max-statements": [2, 100] + "complexity": [2, 55], + "max-statements": [2, 115], + "no-console": 0, + "no-empty": 0, + "no-extra-semi": 0, + "no-fallthrough": 0, + "no-inner-declarations": 0, + "no-mixed-spaces-and-tabs": 0, + "no-redeclare": 0, + "no-unreachable": 1, + "no-unused-vars": 0, } } diff --git a/.travis.yml b/.travis.yml index ce6f1da0..f12ed79f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: node_js node_js: "6" before_script: + - npm run lint - npm install -g gulp script: - gulp diff --git a/lib/graph3d/Graph3d.js b/lib/graph3d/Graph3d.js index b0cbe8a0..e355c9db 100755 --- a/lib/graph3d/Graph3d.js +++ b/lib/graph3d/Graph3d.js @@ -12,13 +12,13 @@ var Settings = require('./Settings'); /// enumerate the available styles -Graph3d.STYLE = Settings.STYLE; +Graph3d.STYLE = Settings.STYLE; /** * Following label is used in the settings to describe values which should be * determined by the code while running, from the current data and graph style. - * + * * Using 'undefined' directly achieves the same thing, but this is more * descriptive by describing the intent. */ @@ -524,7 +524,7 @@ Graph3d.prototype._dataInitialize = function (rawData, style) { } } - + // set the scale dependent on the ranges. this._setScale(); }; @@ -699,7 +699,6 @@ Graph3d.prototype.create = function () { var onclick = function(event) {me._onClick(event);}; // TODO: these events are never cleaned up... can give a 'memory leakage' - util.addEventListener(this.frame.canvas, 'keydown', onkeydown); util.addEventListener(this.frame.canvas, 'mousedown', onmousedown); util.addEventListener(this.frame.canvas, 'touchstart', ontouchstart); util.addEventListener(this.frame.canvas, 'mousewheel', onmousewheel); @@ -902,7 +901,6 @@ Graph3d.prototype.setPointDrawingMethod = function() { default: throw new Error('Can not determine point drawing method ' + 'for graph style \'' + this.style + '\''); - break; } this._pointDrawingMethod = method; @@ -1338,7 +1336,7 @@ Graph3d.prototype._redrawAxis = function() { if (this.showYAxis) { xText = (armVector.y > 0) ? xRange.min : xRange.max; point3d = new Point3d(xText, y, zRange.min); - var msg = ' ' + this.yValueLabel(y) + ' '; + var msg = ' ' + this.yValueLabel(y) + ' '; this.drawAxisLabelY(ctx, point3d, msg, armAngle, textMargin); } diff --git a/lib/network/modules/LayoutEngine.js b/lib/network/modules/LayoutEngine.js index 2f4addfc..14a281e2 100644 --- a/lib/network/modules/LayoutEngine.js +++ b/lib/network/modules/LayoutEngine.js @@ -327,7 +327,6 @@ class LayoutEngine { // if the user defined some levels but not all, alert and run without hierarchical layout if (undefinedLevel === true && definedLevel === true) { throw new Error('To use the hierarchical layout, nodes require either no predefined levels or levels have to be defined for all nodes.'); - return; } else { // define levels if undefined by the users. Based on hubsize. diff --git a/lib/timeline/DateUtil.js b/lib/timeline/DateUtil.js index 5ff46f41..f361c7ee 100644 --- a/lib/timeline/DateUtil.js +++ b/lib/timeline/DateUtil.js @@ -500,7 +500,6 @@ exports.isHidden = function(time, hiddenDates) { if (time >= startDate && time < endDate) { // if the start is entering a hidden zone return {hidden: true, startDate: startDate, endDate: endDate}; - break; } } return {hidden: false, startDate: startDate, endDate: endDate}; diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index be95aa7d..972db387 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -1828,8 +1828,8 @@ ItemSet.prototype._onGroupDragEnd = function (event) { var switchGroup = dataset.get(newOrder[curPos]); var shouldBeGroup = dataset.get(origOrder[curPos]); me.options.groupOrderSwap(switchGroup, shouldBeGroup, dataset); - groupsData.update(switchGroup); - groupsData.update(shouldBeGroup); + dataset.update(switchGroup); + dataset.update(shouldBeGroup); var switchGroupId = newOrder[curPos]; newOrder[curPos] = origOrder[curPos]; diff --git a/lib/timeline/component/item/Item.js b/lib/timeline/component/item/Item.js index 5ddbd736..e41ef781 100644 --- a/lib/timeline/component/item/Item.js +++ b/lib/timeline/component/item/Item.js @@ -18,7 +18,7 @@ function Item (data, conversion, options) { this.data = data; this.dom = null; this.conversion = conversion || {}; - this.options = options || {}; + this.options = options || {}; this.selected = false; this.displayed = false; this.groupShowing = true; @@ -85,7 +85,7 @@ Item.prototype.setData = function(data) { remove: this.data.editable } } - else if(typeof options.editable === 'object') { + else if(typeof this.options.editable === 'object') { this.editable = {}; util.selectiveExtend(['updateTime', 'updateGroup', 'remove'], this.editable, data.editable); } diff --git a/package.json b/package.json index 8326d010..bed62546 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "scripts": { "test": "mocha", "build": "gulp", + "lint": "eslint lib", "watch": "gulp watch", "watch-dev": "gulp watch --bundle" }, @@ -45,8 +46,10 @@ }, "devDependencies": { "async": "^2.1.4", + "babel-eslint": "^7.1.1", "babelify": "^7.3.0", "clean-css": "^4.0.2", + "eslint": "^3.15.0", "gulp": "^3.9.1", "gulp-clean-css": "^2.3.2", "gulp-concat": "^2.6.1",