]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Use gulp-eslint instead of gulp-jshint
authorSimon Brunel <simonbrunel@users.noreply.github.com>
Fri, 2 Sep 2016 19:56:22 +0000 (21:56 +0200)
committerSimon Brunel <simonbrunel@users.noreply.github.com>
Sat, 3 Sep 2016 16:42:22 +0000 (18:42 +0200)
Change the linter in gulp tasks to be consistent with Code Climate results which are based on ESLint using .eslintrc options. However, defaults Code Climate rules are too strict, so turn as warnings the 'complexity' and 'max-statements' rules (other errors has been fixed). Note that the Gulp task name has been changed for `gulp lint`.

.eslintrc
README.md
docs/10-Notes.md
gulpfile.js
package.json
src/controllers/controller.line.js
src/core/core.datasetController.js
src/core/core.helpers.js
src/scales/scale.time.js
test/core.layoutService.tests.js

index 9faa37508e533c82089e0485dd9e9907370a309d..cb5b0d49e3965f72b37db4d2f155fe8c9417bd77 100644 (file)
--- a/.eslintrc
+++ b/.eslintrc
@@ -57,7 +57,6 @@ rules:
   no-case-declarations: 2
   no-div-regex: 2
   no-else-return: 0
-  no-empty-label: 2
   no-empty-pattern: 2
   no-eq-null: 2
   no-eval: 2
index 79695200d6fe66fe8ea206355edacabe75e2daf8..49d09c0174644d2013f71a1860de15efa9efd8df 100644 (file)
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ To build, run `gulp build`.
 
 To test, run `gulp test`.
 
-To test against code standards, run `gulp jshint`.
+To test against code standards, run `gulp lint`.
 
 More information on building and testing can be found in [gulpfile.js](gulpfile.js).
 
index fbeed85fd7b718bda3b0b0e8f30ca073518b72d0..5ca1670a51c1248d11575ee98b935da6a33a9295 100644 (file)
@@ -34,7 +34,7 @@ New contributions to the library are welcome, but we ask that you please follow
 
 - Use tabs for indentation, not spaces.
 - Only change the individual files in `/src`.
-- Check that your code will pass `jshint` code standards, `gulp jshint` will run this for you.
+- Check that your code will pass `eslint` code standards, `gulp lint` will run this for you.
 - Check that your code will pass tests, `gulp test` will run tests for you.
 - Keep pull requests concise, and document new functionality in the relevant `.md` file.
 - Consider whether your changes are useful for all users, or if creating a Chart.js plugin would be more appropriate.
index 14a2e1df596a76a1b135df6aece138d69f388723..b3dab98d11a3b3583a8d8897c62efc078b241775 100644 (file)
@@ -1,23 +1,23 @@
-var gulp = require('gulp'),
-  concat = require('gulp-concat'),
-  file = require('gulp-file'),
-  uglify = require('gulp-uglify'),
-  util = require('gulp-util'),
-  jshint = require('gulp-jshint'),
-  size = require('gulp-size'),
-  connect = require('gulp-connect'),
-  replace = require('gulp-replace'),
-  htmlv = require('gulp-html-validator'),
-  insert = require('gulp-insert'),
-  zip = require('gulp-zip'),
-  exec = require('child_process').exec,
-  package = require('./package.json'),
-  karma = require('gulp-karma'),
-  browserify = require('browserify'),
-  streamify = require('gulp-streamify'),
-  source = require('vinyl-source-stream'),
-  merge = require('merge-stream'),
-  collapse = require('bundle-collapser/plugin');
+var gulp = require('gulp');
+var concat = require('gulp-concat');
+var connect = require('gulp-connect');
+var eslint = require('gulp-eslint');
+var file = require('gulp-file');
+var htmlv = require('gulp-html-validator');
+var insert = require('gulp-insert');
+var replace = require('gulp-replace');
+var size = require('gulp-size');
+var streamify = require('gulp-streamify');
+var uglify = require('gulp-uglify');
+var util = require('gulp-util');
+var zip = require('gulp-zip');
+var exec = require('child_process').exec;
+var karma = require('gulp-karma');
+var browserify = require('browserify');
+var source = require('vinyl-source-stream');
+var merge = require('merge-stream');
+var collapse = require('bundle-collapser/plugin');
+var package = require('./package.json');
 
 var srcDir = './src/';
 var outDir = './dist/';
@@ -43,7 +43,7 @@ var testFiles = [
   // Disable tests which need to be rewritten based on changes introduced by
   // the following changes: https://github.com/chartjs/Chart.js/pull/2346
   '!./test/core.layoutService.tests.js',
-  '!./test/defaultConfig.tests.js',
+  '!./test/defaultConfig.tests.js'
 ];
 
 gulp.task('bower', bowerTask);
@@ -51,8 +51,8 @@ gulp.task('build', buildTask);
 gulp.task('package', packageTask);
 gulp.task('coverage', coverageTask);
 gulp.task('watch', watchTask);
-gulp.task('jshint', jshintTask);
-gulp.task('test', ['jshint', 'validHTML', 'unittest']);
+gulp.task('lint', lintTask);
+gulp.task('test', ['lint', 'validHTML', 'unittest']);
 gulp.task('size', ['library-size', 'module-sizes']);
 gulp.task('server', serverTask);
 gulp.task('validHTML', validHTMLTask);
@@ -130,11 +130,25 @@ function packageTask() {
   .pipe(gulp.dest(outDir));
 }
 
-function jshintTask() {
-  return gulp.src(srcDir + '**/*.js')
-    .pipe(jshint('config.jshintrc'))
-    .pipe(jshint.reporter('jshint-stylish'))
-    .pipe(jshint.reporter('fail'));
+function lintTask() {
+  var files = [
+    srcDir + '**/*.js',
+  ];
+
+  // NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict
+  // compare to what the current codebase can support, and since it's not straightforward
+  // to fix, let's turn them as warnings and rewrite code later progressively.
+  var options = {
+    rules: {
+      'complexity': [1, 6],
+      'max-statements': [1, 30]
+    }
+  };
+
+  return gulp.src(files)
+    .pipe(eslint(options))
+    .pipe(eslint.format())
+    .pipe(eslint.failAfterError());
 }
 
 function validHTMLTask() {
index ed6b6f921df599cb40f1b4a4099bcbc520dba0d7..eb383d71374fb6d65e4de3c1f37319db8c0a0722 100644 (file)
     "gulp": "3.9.x",
     "gulp-concat": "~2.1.x",
     "gulp-connect": "~2.0.5",
+    "gulp-eslint": "^2.0.0",
     "gulp-file": "^0.3.0",
     "gulp-html-validator": "^0.0.2",
     "gulp-insert": "~0.5.0",
-    "gulp-jshint": "~1.5.1",
     "gulp-karma": "0.0.4",
     "gulp-replace": "^0.5.4",
     "gulp-size": "~0.4.0",
@@ -30,7 +30,6 @@
     "gulp-zip": "~3.2.0",
     "jasmine": "^2.3.2",
     "jasmine-core": "^2.3.4",
-    "jshint-stylish": "~2.1.0",
     "karma": "^0.12.37",
     "karma-browserify": "^5.0.1",
     "karma-chrome-launcher": "^0.2.0",
index a7746ee27e3f068e27e3563aceb5a80fb4d05b63..906cc8b916a6490bcdb1d124c3da9394e1120c27 100644 (file)
@@ -260,7 +260,7 @@ module.exports = function(Chart) {
                                return Math.max(Math.min(pt, max), min);
                        }
 
-                       if (meta.dataset._model.cubicInterpolationMode == 'monotone') {
+                       if (meta.dataset._model.cubicInterpolationMode === 'monotone') {
                                helpers.splineCurveMonotone(points);
                        }
                        else {
index 02af1471debe75e23a4f43497176777e38b29b81..4318a9c951d48b9eaf07992c575f9305535ea17d 100644 (file)
@@ -7,7 +7,7 @@ module.exports = function(Chart) {
 
        // Base class for all dataset controllers (line, bar, etc)
        Chart.DatasetController = function(chart, datasetIndex) {
-               this.initialize.call(this, chart, datasetIndex);
+               this.initialize(chart, datasetIndex);
        };
 
        helpers.extend(Chart.DatasetController.prototype, {
@@ -157,9 +157,9 @@ module.exports = function(Chart) {
                        model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
                        model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
                }
-               
+
     });
-       
+
 
        Chart.DatasetController.extend = helpers.inherits;
 };
\ No newline at end of file
index c00aee6fa767f044a029eb0d2d6696476c2c0045..0cf16f171c89fa46e8be6608033a304af9db8b3c 100644 (file)
@@ -238,7 +238,7 @@ module.exports = function(Chart) {
                return function() {
                        return id++;
                };
-       })();
+       }());
        //-- Math methods
        helpers.isNumber = function(n) {
                return !isNaN(parseFloat(n)) && isFinite(n);
@@ -366,7 +366,7 @@ module.exports = function(Chart) {
                        }
                        if (!pointBefore || pointBefore.model.skip) pointCurrent.mK = pointCurrent.deltaK;
                        else if (!pointAfter || pointAfter.model.skip) pointCurrent.mK = pointBefore.deltaK;
-                       else if (this.sign(pointBefore.deltaK) != this.sign(pointCurrent.deltaK)) pointCurrent.mK = 0;
+                       else if (this.sign(pointBefore.deltaK) !== this.sign(pointCurrent.deltaK)) pointCurrent.mK = 0;
                        else pointCurrent.mK = (pointBefore.deltaK + pointCurrent.deltaK) / 2;
                }
 
@@ -376,8 +376,7 @@ module.exports = function(Chart) {
                        pointCurrent = pointsWithTangents[i];
                        pointAfter = pointsWithTangents[i + 1];
                        if (pointCurrent.model.skip || pointAfter.model.skip) continue;
-                       if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON))
-                       {
+                       if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON)) {
                                pointCurrent.mK = pointAfter.mK = 0;
                                continue;
                        }
@@ -660,7 +659,7 @@ module.exports = function(Chart) {
                        function(callback) {
                                return window.setTimeout(callback, 1000 / 60);
                        };
-       })();
+       }());
        helpers.cancelAnimFrame = (function() {
                return window.cancelAnimationFrame ||
                        window.webkitCancelAnimationFrame ||
@@ -670,7 +669,7 @@ module.exports = function(Chart) {
                        function(callback) {
                                return window.clearTimeout(callback, 1000 / 60);
                        };
-       })();
+       }());
        //-- DOM methods
        helpers.getRelativePosition = function(evt, chart) {
                var mouseX, mouseY;
@@ -751,7 +750,7 @@ module.exports = function(Chart) {
                if (typeof(styleValue) === 'string') {
                        valueInPixels = parseInt(styleValue, 10);
 
-                       if (styleValue.indexOf('%') != -1) {
+                       if (styleValue.indexOf('%') !== -1) {
                                // percentage * size in dimension
                                valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
                        }
@@ -802,15 +801,17 @@ module.exports = function(Chart) {
        };
        helpers.getMaximumWidth = function(domNode) {
                var container = domNode.parentNode;
-               var padding = parseInt(helpers.getStyle(container, 'padding-left')) + parseInt(helpers.getStyle(container, 'padding-right'));
-               var w = container.clientWidth - padding;
+               var paddingLeft = parseInt(helpers.getStyle(container, 'padding-left'), 10);
+               var paddingRight = parseInt(helpers.getStyle(container, 'padding-right'), 10);
+               var w = container.clientWidth - paddingLeft - paddingRight;
                var cw = helpers.getConstraintWidth(domNode);
                return isNaN(cw)? w : Math.min(w, cw);
        };
        helpers.getMaximumHeight = function(domNode) {
                var container = domNode.parentNode;
-               var padding = parseInt(helpers.getStyle(container, 'padding-top')) + parseInt(helpers.getStyle(container, 'padding-bottom'));
-               var h = container.clientHeight - padding;
+               var paddingTop = parseInt(helpers.getStyle(container, 'padding-top'), 10);
+               var paddingBottom = parseInt(helpers.getStyle(container, 'padding-bottom'), 10);
+               var h = container.clientHeight - paddingTop - paddingBottom;
                var ch = helpers.getConstraintHeight(domNode);
                return isNaN(ch)? h : Math.min(h, ch);
        };
@@ -964,7 +965,7 @@ module.exports = function(Chart) {
 
                (hiddenIframe.contentWindow || hiddenIframe).onresize = function() {
                        if (callback) {
-                               callback();
+                               return callback();
                        }
                };
        };
@@ -985,7 +986,7 @@ module.exports = function(Chart) {
        helpers.arrayEquals = function(a0, a1) {
                var i, ilen, v0, v1;
 
-               if (!a0 || !a1 || a0.length != a1.length) {
+               if (!a0 || !a1 || a0.length !== a1.length) {
                        return false;
                }
 
@@ -997,7 +998,7 @@ module.exports = function(Chart) {
                                if (!helpers.arrayEquals(v0, v1)) {
                                        return false;
                                }
-                       } else if (v0 != v1) {
+                       } else if (v0 !== v1) {
                                // NOTE: two different object instances will never be equal: {x:20} != {x:20}
                                return false;
                        }
index ab935a12a0a0ca1f5157c67bc7a8a8ec6dc3bfe1..c7b64cbd3b9c5e33b43d8275d6583d66625eb9f4 100755 (executable)
@@ -80,7 +80,7 @@ module.exports = function(Chart) {
                                return null;
             }
             
-                       if (typeof this.labelMoments[datasetIndex] != 'undefined') {
+                       if (typeof this.labelMoments[datasetIndex] !== 'undefined') {
                                return this.labelMoments[datasetIndex][index];
                        }
 
index 819519f4806aaf060010235d55cb4345536d9ac5..8296e977e162749490946ee982f9c9af08cce113 100644 (file)
@@ -230,10 +230,10 @@ describe('Test the layout service', function() {
                expect(chart.scales.xScale1.right).toBeCloseToPixel(512);
                expect(chart.scales.xScale1.top).toBeCloseToPixel(484);
 
-               expect(chart.scales.xScale2.bottom).toBeCloseToPixel(28);
+               expect(chart.scales.xScale2.bottom).toBeCloseToPixel(60);
                expect(chart.scales.xScale2.left).toBeCloseToPixel(0);
                expect(chart.scales.xScale2.right).toBeCloseToPixel(512);
-               expect(chart.scales.xScale2.top).toBeCloseToPixel(0);
+               expect(chart.scales.xScale2.top).toBeCloseToPixel(32);
 
                // Is yScale at the right spot
                expect(chart.scales.yScale.bottom).toBeCloseToPixel(484);