From 221757c8d5ce3d5648ed62a1ecbd795c3829d7fc Mon Sep 17 00:00:00 2001 From: wimrijnders Date: Sun, 16 Jul 2017 23:05:49 +0200 Subject: [PATCH] Enable 'eslint' (#3230) * First working version of eslint enabled with gulp * Tryout of eslint with graph3d files * Cleanup of gulp and eslint files. * Completed test by linting graph3d * Disable travis linting for now * Remove global cmd param from .travis.yml --- .eslintrc | 12 +++++++++--- .travis.yml | 4 ++-- gulpfile.js | 35 +++++++++++++++++++++++++++++++++++ lib/graph3d/Camera.js | 5 ++--- lib/graph3d/DataGroup.js | 1 - lib/graph3d/Filter.js | 5 +---- lib/graph3d/Graph3d.js | 27 ++++++++++----------------- lib/graph3d/Point3d.js | 2 +- lib/graph3d/Slider.js | 4 ++-- lib/graph3d/StepNumber.js | 2 +- package.json | 3 +-- 11 files changed, 64 insertions(+), 36 deletions(-) diff --git a/.eslintrc b/.eslintrc index 4d6a230f..f442eda4 100644 --- a/.eslintrc +++ b/.eslintrc @@ -6,13 +6,18 @@ "mocha": true }, - "parser": "babel-eslint", + "parserOptions": { + "sourceType": "module", + }, "extends": "eslint:recommended", "rules": { "complexity": [2, 55], "max-statements": [2, 115], + "no-unreachable": 1, +/* + // some disabled options which might be useful "no-console": 0, "no-empty": 0, "no-extra-semi": 0, @@ -20,8 +25,9 @@ "no-inner-declarations": 0, "no-mixed-spaces-and-tabs": 0, "no-redeclare": 0, - "no-unreachable": 1, "no-unused-vars": 0, - "no-useless-escape": 0, + "no-useless-escape": 0, + // following will flag presence of console.log as error. + "no-console": ["error", { allow: ["warn", "error"] }], } } diff --git a/.travis.yml b/.travis.yml index 3948301f..063a3f91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,8 @@ addons: - libgif-dev - g++-4.8 before_script: - - npm run lint - - npm install -g gulp +# - npm run lint + - npm install gulp script: - gulp - npm test diff --git a/gulpfile.js b/gulpfile.js index 44acd9f6..6412c7dc 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,6 +1,7 @@ var fs = require('fs'); var async = require('async'); var gulp = require('gulp'); +var eslint = require('gulp-eslint'); var gutil = require('gulp-util'); var concat = require('gulp-concat'); var cleanCSS = require('gulp-clean-css'); @@ -216,5 +217,39 @@ gulp.task('watch', watchTasks, function () { gulp.watch(['index.js', 'lib/**/*'], watchTasks); }); + +//////////////////////////////////////////////////////////////////////////////////////// +// Linting +// +// Linting has intentionally NOT been added yet to the default task; there are simply +// too many errors at the moment to make this comfortable. Run it separately with: +// +// > gulp lint or > gulp lint- +// +// This is set up so that 'gulp lint' runs the linting over the complete lib directory. +// You can also run linting on the separate modules, e.g. 'gulp lint-network' for just +// the network module. Scan the tasks below for the available lint commands. +// +// Note that currently a separate lint is missing for Graph2d, DataSet and DataGroup. +//////////////////////////////////////////////////////////////////////////////////////// + + +function runLintTask(pathPrefix) { + return gulp.src([ pathPrefix + '/**/*.js', '!node_modules/**']) + .pipe(eslint()) + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); +} + +gulp.task('lint', function () {return runLintTask('lib');}); +gulp.task('lint-timeline', function () {return runLintTask('lib/timeline');}); +gulp.task('lint-network', function () {return runLintTask('lib/network');}); +gulp.task('lint-graph3d', function () {return runLintTask('lib/graph3d');}); + + +//////////////////////////////////////////////////////////////////////////////////////// +// End Linting +//////////////////////////////////////////////////////////////////////////////////////// + // The default task (called when you run `gulp`) gulp.task('default', ['clean', 'bundle', 'minify']); diff --git a/lib/graph3d/Camera.js b/lib/graph3d/Camera.js index b06381b4..73adfe56 100644 --- a/lib/graph3d/Camera.js +++ b/lib/graph3d/Camera.js @@ -47,11 +47,11 @@ Camera.prototype.setOffset = function(x, y) { this.calculateCameraOrientation(); }; + /** * Get camera offset by horizontal and vertical - * @return {Point3d} x - horizontal offset, y - vertical offset, z - not used */ -Camera.prototype.getOffset = function(x, y) { +Camera.prototype.getOffset = function() { return this.cameraOffset; }; @@ -165,7 +165,6 @@ Camera.prototype.calculateCameraOrientation = function() { this.cameraRotation.z = -this.armRotation.horizontal; var xa = this.cameraRotation.x; - var ya = this.cameraRotation.y; var za = this.cameraRotation.z; var dx = this.cameraOffset.x; var dy = this.cameraOffset.y; diff --git a/lib/graph3d/DataGroup.js b/lib/graph3d/DataGroup.js index 83823085..d3fadae3 100644 --- a/lib/graph3d/DataGroup.js +++ b/lib/graph3d/DataGroup.js @@ -1,6 +1,5 @@ var DataSet = require('../DataSet'); var DataView = require('../DataView'); -var Point3d = require('./Point3d'); var Range = require('./Range'); diff --git a/lib/graph3d/Filter.js b/lib/graph3d/Filter.js index 56f0c453..0a4ac584 100644 --- a/lib/graph3d/Filter.js +++ b/lib/graph3d/Filter.js @@ -35,7 +35,7 @@ function Filter (dataGroup, column, graph) { else { this.loaded = true; } -}; +} /** @@ -176,9 +176,6 @@ Filter.prototype.loadInBackground = function(index) { var frame = this.graph.frame; if (index < this.values.length) { - var dataPointsTemp = this._getDataPoints(index); - //this.graph.redrawInfo(); // TODO: not neat - // create a progress box if (frame.progress === undefined) { frame.progress = document.createElement('DIV'); diff --git a/lib/graph3d/Graph3d.js b/lib/graph3d/Graph3d.js index 40b1ea7e..7ce25fd5 100755 --- a/lib/graph3d/Graph3d.js +++ b/lib/graph3d/Graph3d.js @@ -1,14 +1,10 @@ var Emitter = require('emitter-component'); -var DataSet = require('../DataSet'); -var DataView = require('../DataView'); var util = require('../util'); var Point3d = require('./Point3d'); var Point2d = require('./Point2d'); -var Camera = require('./Camera'); var Filter = require('./Filter'); var Slider = require('./Slider'); var StepNumber = require('./StepNumber'); -var Range = require('./Range'); var Settings = require('./Settings'); var DataGroup = require('./DataGroup'); @@ -439,7 +435,7 @@ Graph3d.prototype.getDataPoints = function(data) { Graph3d.prototype._getDataPoints = function (data) { // TODO: store the created matrix dataPoints in the filters instead of // reloading each time. - var x, y, i, z, obj, point; + var x, y, i, obj; var dataPoints = []; @@ -492,7 +488,7 @@ Graph3d.prototype._getDataPoints = function (data) { // Add next member points for line drawing for (i = 0; i < dataPoints.length; i++) { if (i > 0) { - dataPoints[i - 1].pointNext = dataPoints[i];; + dataPoints[i - 1].pointNext = dataPoints[i]; } } } @@ -692,8 +688,6 @@ Graph3d.prototype.setData = function (data) { * @param {Object} options */ Graph3d.prototype.setOptions = function (options) { - var cameraPosition = undefined; - this.animationStop(); Settings.setOptions(options, this); @@ -913,7 +907,6 @@ Graph3d.prototype._redrawLegend = function() { var step = new StepNumber(legendMin, legendMax, (legendMax-legendMin)/5, true); step.start(true); - var y; var from; var to; while (!step.end()) { @@ -1125,6 +1118,7 @@ Graph3d.prototype._redrawAxis = function() { var xRange = this.xRange; var yRange = this.yRange; var zRange = this.zRange; + var point3d; // draw x-grid lines ctx.lineWidth = 1; @@ -1152,8 +1146,8 @@ Graph3d.prototype._redrawAxis = function() { if (this.showXAxis) { yText = (armVector.x > 0) ? yRange.min : yRange.max; - var point3d = new Point3d(x, yText, zRange.min); - var msg = ' ' + this.xValueLabel(x) + ' '; + point3d = new Point3d(x, yText, zRange.min); + let msg = ' ' + this.xValueLabel(x) + ' '; this.drawAxisLabelX(ctx, point3d, msg, armAngle, textMargin); } @@ -1187,7 +1181,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) + ' '; + let msg = ' ' + this.yValueLabel(y) + ' '; this.drawAxisLabelY(ctx, point3d, msg, armAngle, textMargin); } @@ -1213,7 +1207,7 @@ Graph3d.prototype._redrawAxis = function() { to = new Point2d(from2d.x - textMargin, from2d.y); this._line(ctx, from2d, to, this.axisColor); - var msg = this.zValueLabel(z) + ' '; + let msg = this.zValueLabel(z) + ' '; this.drawAxisLabelZ(ctx, from3d, msg, 5); step.next(); @@ -1339,7 +1333,7 @@ Graph3d.prototype._getStrokeWidth = function(point) { * Draw a bar element in the view with the given properties. */ Graph3d.prototype._redrawBar = function(ctx, point, xWidth, yWidth, color, borderColor) { - var i, j, surface; + var surface; // calculate all corner points var me = this; @@ -1377,7 +1371,7 @@ Graph3d.prototype._redrawBar = function(ctx, point, xWidth, yWidth, color, borde point.surfaces = surfaces; // calculate the distance of each of the surface centers to the camera - for (j = 0; j < surfaces.length; j++) { + for (let j = 0; j < surfaces.length; j++) { surface = surfaces[j]; var transCenter = this._convertPointToTranslation(surface.center); surface.dist = this.showPerspective ? transCenter.length() : -transCenter.z; @@ -1404,7 +1398,7 @@ Graph3d.prototype._redrawBar = function(ctx, point, xWidth, yWidth, color, borde ctx.strokeStyle = borderColor; ctx.fillStyle = color; // NOTE: we start at j=2 instead of j=0 as we don't need to draw the two surfaces at the backside - for (j = 2; j < surfaces.length; j++) { + for (let j = 2; j < surfaces.length; j++) { surface = surfaces[j]; this._polygon(ctx, surface.corners); } @@ -1652,7 +1646,6 @@ Graph3d.prototype._redrawSurfaceGraphPoint = function(ctx, point) { var topSideVisible = true; var fillStyle; var strokeStyle; - var lineWidth; if (this.showGrayBottom || this.showShadow) { // calculate the cross product of the two vectors from center diff --git a/lib/graph3d/Point3d.js b/lib/graph3d/Point3d.js index 0892e693..4bf6a574 100644 --- a/lib/graph3d/Point3d.js +++ b/lib/graph3d/Point3d.js @@ -8,7 +8,7 @@ function Point3d(x, y, z) { this.x = x !== undefined ? x : 0; this.y = y !== undefined ? y : 0; this.z = z !== undefined ? z : 0; -}; +} /** * Subtract the two provided points, returns a-b diff --git a/lib/graph3d/Slider.js b/lib/graph3d/Slider.js index f6f21ecc..21299022 100644 --- a/lib/graph3d/Slider.js +++ b/lib/graph3d/Slider.js @@ -184,7 +184,7 @@ Slider.prototype.setPlayInterval = function(interval) { * Retrieve the current play interval * @return {Number} interval The interval in milliseconds */ -Slider.prototype.getPlayInterval = function(interval) { +Slider.prototype.getPlayInterval = function() { return this.playInterval; }; @@ -333,7 +333,7 @@ Slider.prototype._onMouseMove = function (event) { }; -Slider.prototype._onMouseUp = function (event) { +Slider.prototype._onMouseUp = function (event) { // eslint-disable-line no-unused-vars this.frame.style.cursor = 'auto'; // remove event listeners diff --git a/lib/graph3d/StepNumber.js b/lib/graph3d/StepNumber.js index 9675b4f8..f49529f8 100644 --- a/lib/graph3d/StepNumber.js +++ b/lib/graph3d/StepNumber.js @@ -33,7 +33,7 @@ function StepNumber(start, end, step, prettyStep) { this._current = 0; this.setRange(start, end, step, prettyStep); -}; +} /** diff --git a/package.json b/package.json index a3698d84..dcad9ccf 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ "devDependencies": { "async": "^2.1.4", "babel-core": "^6.6.5", - "babel-eslint": "^7.1.1", "babel-loader": "^6.2.4", "babel-polyfill": "^6.22.0", "babel-plugin-transform-es3-member-expression-literals": "^6.22.0", @@ -55,9 +54,9 @@ "clean-css": "^4.0.2", "eslint": "^4.2.0", "gulp": "^3.9.1", + "gulp-eslint": "^4.0.0", "gulp-clean-css": "^3.7.0", "gulp-concat": "^2.6.1", - "gulp-eslint": "^4.0.0", "gulp-rename": "^1.2.2", "gulp-util": "^3.0.8", "jsdom": "9.9.1",