From: Dan Vanderkam Date: Fri, 10 Aug 2012 16:16:24 +0000 (-0400) Subject: fix all lint errors X-Git-Tag: v1.0.0~199 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=42a9ebb8f492d2541a3904894447a7c74ba4cfd5;p=dygraphs.git fix all lint errors --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 5286ad5..571191c 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -241,9 +241,9 @@ DygraphCanvasRenderer.prototype._createIEClipArea = function() { * skip over points with missing yVals. */ DygraphCanvasRenderer._getIteratorPredicate = function(connectSeparatedPoints) { - return connectSeparatedPoints - ? DygraphCanvasRenderer._predicateThatSkipsEmptyPoints - : null; + return connectSeparatedPoints ? + DygraphCanvasRenderer._predicateThatSkipsEmptyPoints : + null; }; DygraphCanvasRenderer._predicateThatSkipsEmptyPoints = @@ -335,8 +335,8 @@ DygraphCanvasRenderer._drawSeries = function(e, if (point.canvasy === null || point.canvasy != point.canvasy) { if (stepPlot && prevCanvasX !== null) { // Draw a horizontal line to the start of the missing data - ctx.moveTo(prevX, prevY); - ctx.lineTo(point.canvasx, prevY); + ctx.moveTo(prevCanvasX, prevCanvasY); + ctx.lineTo(point.canvasx, prevCanvasY); } prevCanvasX = prevCanvasY = null; } else { @@ -401,7 +401,7 @@ DygraphCanvasRenderer._drawPointsOnLine = function( e.dygraph, e.setName, ctx, cb[0], cb[1], color, pointSize); ctx.restore(); } -} +}; /** * Attaches canvas coordinates to the points array. @@ -452,6 +452,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function(opt_seriesName, opt_ var sets = this.layout.points; var setNames = this.layout.setNames; var setCount = setNames.length; + var setName; this.colors = this.dygraph_.colorsMap_; @@ -464,7 +465,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function(opt_seriesName, opt_ var setPlotters = {}; // series name -> plotter fn. for (i = 0; i < setNames.length; i++) { - var setName = setNames[i]; + setName = setNames[i]; var setPlotter = this.attr_("plotter", setName); if (setPlotter == plotter_attr) continue; // not specialized. @@ -476,7 +477,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function(opt_seriesName, opt_ var is_last = (i == plotters.length - 1); for (var j = 0; j < sets.length; j++) { - var setName = setNames[j]; + setName = setNames[j]; if (opt_seriesName && setName != opt_seriesName) continue; var points = sets[j]; @@ -572,7 +573,7 @@ DygraphCanvasRenderer._linePlotter = function(e) { drawPointCallback, pointSize ); -} +}; /** * Draws the shaded error bars/confidence intervals for each series. @@ -649,7 +650,7 @@ DygraphCanvasRenderer._errorPlotter = function(e) { prevX = point.canvasx; } ctx.fill(); -} +}; /** * Draws the shaded regions when "fillGraph" is set. Not to be confused with diff --git a/dygraph-interaction-model.js b/dygraph-interaction-model.js index 5185b3d..4df6799 100644 --- a/dygraph-interaction-model.js +++ b/dygraph-interaction-model.js @@ -485,7 +485,7 @@ Dygraph.Interaction.moveTouch = function(event, g, context) { * @private */ Dygraph.Interaction.endTouch = function(event, g, context) { - if (event.touches.length != 0) { + if (event.touches.length !== 0) { // this is effectively a "reset" Dygraph.Interaction.startTouch(event, g, context); } diff --git a/dygraph-layout.js b/dygraph-layout.js index e25afba..7e08e3e 100644 --- a/dygraph-layout.js +++ b/dygraph-layout.js @@ -277,7 +277,7 @@ DygraphLayout.parseFloat_ = function(val) { // Assume it's a number or NaN. If it's something else, I'll be shocked. return val; -} +}; DygraphLayout.prototype._evaluateLineTicks = function() { var i, tick, label, pos; diff --git a/dygraph-range-selector.js b/dygraph-range-selector.js index 61626c9..0342ea7 100644 --- a/dygraph-range-selector.js +++ b/dygraph-range-selector.js @@ -221,7 +221,8 @@ DygraphRangeSelector.prototype.initInteraction_ = function() { } Dygraph.cancelEvent(e); var delX = e.screenX - xLast; - if (Math.abs(delX) < 4 || e.screenX == 0) { // First iPad move event seems to have screenX = 0 + if (Math.abs(delX) < 4 || e.screenX === 0) { + // First iPad move event seems to have screenX = 0 return true; } xLast = e.screenX; diff --git a/dygraph-utils.js b/dygraph-utils.js index b73475d..e942f0c 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -696,7 +696,7 @@ Dygraph.Iterator = function(array, start, length, predicate) { this.end_ = Math.min(array.length, start + length); this.nextIdx_ = start - 1; // use -1 so initial advance works. this.next(); // ignoring result. -} +}; Dygraph.Iterator.prototype.next = function() { if (!this.hasNext) { @@ -720,7 +720,7 @@ Dygraph.Iterator.prototype.next = function() { this.peek = null; } return obj; -} +}; /** * @private @@ -944,7 +944,7 @@ Dygraph.regularShape_ = function( } ctx.fill(); ctx.stroke(); -} +}; Dygraph.shapeFunction_ = function(sides, rotationRadians, delta) { return function(g, name, ctx, cx, cy, color, radius) { @@ -956,7 +956,7 @@ Dygraph.shapeFunction_ = function(sides, rotationRadians, delta) { Dygraph.DrawPolygon_ = function(sides, rotationRadians, ctx, cx, cy, color, radius, delta) { new Dygraph.RegularShape_(sides, rotationRadians, delta).draw(ctx, cx, cy, radius); -} +}; Dygraph.Circles = { DEFAULT : function(g, name, ctx, canvasx, canvasy, color, radius) { diff --git a/dygraph.js b/dygraph.js index cec7c20..3a8cd32 100644 --- a/dygraph.js +++ b/dygraph.js @@ -437,8 +437,8 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { // Activate plugins. this.plugins_ = []; for (var i = 0; i < Dygraph.PLUGINS.length; i++) { - var plugin = Dygraph.PLUGINS[i]; - var pluginInstance = new plugin(); + var Plugin = Dygraph.PLUGINS[i]; + var pluginInstance = new Plugin(); var pluginDict = { plugin: pluginInstance, events: {}, @@ -482,7 +482,7 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { * @private */ Dygraph.prototype.cascadeEvents_ = function(name, extra_props) { - if (!name in this.eventListeners_) return true; + if (!(name in this.eventListeners_)) return true; // QUESTION: can we use objects & prototypes to speed this up? var e = { @@ -518,11 +518,13 @@ Dygraph.prototype.cascadeEvents_ = function(name, extra_props) { * Axis is an optional parameter. Can be set to 'x' or 'y'. * * The zoomed status for an axis is set whenever a user zooms using the mouse - * or when the dateWindow or valueRange are updated (unless the isZoomedIgnoreProgrammaticZoom - * option is also specified). + * or when the dateWindow or valueRange are updated (unless the + * isZoomedIgnoreProgrammaticZoom option is also specified). */ Dygraph.prototype.isZoomed = function(axis) { - if (axis == null) return this.zoomed_x_ || this.zoomed_y_; + if (axis === null || axis === undefined) { + return this.zoomed_x_ || this.zoomed_y_; + } if (axis === 'x') return this.zoomed_x_; if (axis === 'y') return this.zoomed_y_; throw "axis parameter is [" + axis + "] must be null, 'x' or 'y'."; @@ -570,7 +572,7 @@ Dygraph.prototype.attr_ = function(name, seriesName) { } if (seriesName === this.highlightSet_ && this.user_attrs_.hasOwnProperty('highlightSeriesOpts')) { - sources.push(this.user_attrs_['highlightSeriesOpts']); + sources.push(this.user_attrs_.highlightSeriesOpts); } } } @@ -1521,7 +1523,8 @@ Dygraph.prototype.doUnzoom_ = function() { newValueRanges = []; for (i = 0; i < this.axes_.length; i++) { var axis = this.axes_[i]; - newValueRanges.push(axis.valueRange != null ? axis.valueRange : axis.extremeRange); + newValueRanges.push(axis.valueRange !== null ? + axis.valueRange : axis.extremeRange); } } @@ -1723,7 +1726,7 @@ Dygraph.prototype.findStackedPoint = function(domX, domY) { } } // Stop if the point (domX, py) is above this series' upper edge - if (setIdx == 0 || py < domY) { + if (setIdx === 0 || py < domY) { closestPoint = p1; closestSeries = setIdx; } @@ -1952,7 +1955,7 @@ Dygraph.prototype.setSelection = function(row, opt_seriesName, opt_locked) { point = this.layout_.unstackPointAtIndex(setIdx, row); } - if (!(point.yval === null)) this.selPoints_.push(point); + if (point.yval !== null) this.selPoints_.push(point); } } } else { @@ -3134,7 +3137,7 @@ Dygraph.prototype.parseDataTable_ = function(data) { num = Math.floor((num - 1) / 26); } return shortText; - } + }; var cols = data.getNumberOfColumns(); var rows = data.getNumberOfRows(); diff --git a/lint.sh b/lint.sh index 6c640ad..c316a72 100755 --- a/lint.sh +++ b/lint.sh @@ -5,8 +5,13 @@ # # The zero-argument form lints everything. -jsc_opts='maxerr:10000,devel:true,browser:true' -rhino_opts='maxerr=10000,devel=true,browser=true' +# See jshint/build/jshint-rhino.js for documentation on these parameters. +# devel defines logging globals (i.e. "console.log") +# browser defines standard web browser globals (i.e. "document") +# shadow disables warnings on multiple var definitions in one scope (i.e. two +# loops with "var i") +jsc_opts='maxerr:10000,devel:true,browser:true,shadow:true' +rhino_opts='maxerr=10000,devel=true,browser=true,shadow=true' if [ $# -gt 1 ]; then echo "Usage: $0 [file.js]" @@ -19,6 +24,8 @@ else files=$1 fi +jshint_opts="shadow=false" + if [ -e /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc ]; then # use JSC (Safari/JavaScriptCore) to run JSHint -- much faster than Rhino. echo 'Running JSHint w/ JavaScriptCore (jsc)...' diff --git a/plugins/annotations.js b/plugins/annotations.js index 796d6c3..94a0642 100644 --- a/plugins/annotations.js +++ b/plugins/annotations.js @@ -54,7 +54,7 @@ annotations.prototype.didDrawChart = function(e) { // Early out in the (common) case of zero annotations. var points = g.layout_.annotated_points; - if (!points || points.length == 0) return; + if (!points || points.length === 0) return; var containerDiv = e.canvas.parentNode; var annotationStyle = { diff --git a/plugins/axes.js b/plugins/axes.js index 88d2fc8..1f9c256 100644 --- a/plugins/axes.js +++ b/plugins/axes.js @@ -84,7 +84,7 @@ axes.prototype.detachLabels = function() { axes.prototype.clearChart = function(e) { var g = e.dygraph; this.detachLabels(); -} +}; axes.prototype.willDrawChart = function(e) { var g = e.dygraph; @@ -270,7 +270,7 @@ axes.prototype.willDrawChart = function(e) { } context.restore(); -} +}; return axes; })(); diff --git a/plugins/chart-labels.js b/plugins/chart-labels.js index d6c1095..34775fc 100644 --- a/plugins/chart-labels.js +++ b/plugins/chart-labels.js @@ -109,7 +109,7 @@ var createRotatedDiv = function(g, box, axis, classes, html) { inner_div.appendChild(class_div); div.appendChild(inner_div); return div; -} +}; chart_labels.prototype.layout = function(e) { this.detachLabels_(); @@ -191,7 +191,7 @@ chart_labels.prototype.clearChart = function() { }; chart_labels.prototype.destroy = function() { - detachLabels(); + this.detachLabels_(); }; diff --git a/plugins/grid.js b/plugins/grid.js index 051d13f..6284abb 100644 --- a/plugins/grid.js +++ b/plugins/grid.js @@ -83,7 +83,7 @@ grid.prototype.willDrawChart = function(e) { } ctx.restore(); } -} +}; grid.prototype.destroy = function() { }; diff --git a/plugins/legend.js b/plugins/legend.js index f16e632..5b4a867 100644 --- a/plugins/legend.js +++ b/plugins/legend.js @@ -16,6 +16,8 @@ Current bits of jankiness: */ +/*jshint globalstrict: true */ +/*global Dygraph:false */ "use strict"; @@ -34,6 +36,9 @@ legend.prototype.toString = function() { return "Legend Plugin"; }; +// (defined below) +var generateLegendHTML, generateLegendDashHTML; + /** * This is called during the dygraph constructor, after options have been set * but before the data is available. @@ -133,7 +138,7 @@ legend.prototype.deselect = function(e) { legend.prototype.didDrawChart = function(e) { this.deselect(e); -} +}; // Right edge should be flush with the right edge of the charting area (which // may not be the same as the right edge of the div, if we have two y-axes. @@ -211,8 +216,8 @@ var generateLegendHTML = function(g, x, sel_points, oneEmWidth) { var xOptView = g.optionsViewForAxis_('x'); var xvf = xOptView('valueFormatter'); html = xvf(x, xOptView, labels[0], g); - if(html !== '') { - html += ':'; + if (html !== '') { + html += ':'; } var yOptViews = [];