Browse Source

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
revert-3409-performance
wimrijnders 7 years ago
committed by yotamberk
parent
commit
221757c8d5
11 changed files with 64 additions and 36 deletions
  1. +9
    -3
      .eslintrc
  2. +2
    -2
      .travis.yml
  3. +35
    -0
      gulpfile.js
  4. +2
    -3
      lib/graph3d/Camera.js
  5. +0
    -1
      lib/graph3d/DataGroup.js
  6. +1
    -4
      lib/graph3d/Filter.js
  7. +10
    -17
      lib/graph3d/Graph3d.js
  8. +1
    -1
      lib/graph3d/Point3d.js
  9. +2
    -2
      lib/graph3d/Slider.js
  10. +1
    -1
      lib/graph3d/StepNumber.js
  11. +1
    -2
      package.json

+ 9
- 3
.eslintrc View File

@ -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"] }],
}
}

+ 2
- 2
.travis.yml View File

@ -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

+ 35
- 0
gulpfile.js View File

@ -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-<module name>
//
// 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']);

+ 2
- 3
lib/graph3d/Camera.js View File

@ -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;

+ 0
- 1
lib/graph3d/DataGroup.js View File

@ -1,6 +1,5 @@
var DataSet = require('../DataSet');
var DataView = require('../DataView');
var Point3d = require('./Point3d');
var Range = require('./Range');

+ 1
- 4
lib/graph3d/Filter.js View File

@ -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');

+ 10
- 17
lib/graph3d/Graph3d.js View File

@ -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

+ 1
- 1
lib/graph3d/Point3d.js View File

@ -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

+ 2
- 2
lib/graph3d/Slider.js View File

@ -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

+ 1
- 1
lib/graph3d/StepNumber.js View File

@ -33,7 +33,7 @@ function StepNumber(start, end, step, prettyStep) {
this._current = 0;
this.setRange(start, end, step, prettyStep);
};
}
/**

+ 1
- 2
package.json View File

@ -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",

Loading…
Cancel
Save