From: Dan Vanderkam Date: Sat, 22 Nov 2014 05:52:58 +0000 (-0500) Subject: Turn on more lint warnings; clear up some directives X-Git-Tag: v1.1.0~16^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=refs%2Fheads%2Fjshint;p=dygraphs.git Turn on more lint warnings; clear up some directives --- diff --git a/.jshintrc b/.jshintrc index fb5e562..b50bc1f 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,8 +1,18 @@ { - "browser": true, + "newcap": true, + "noarg": true, "shadow": true, + "strict": true, + "forin": true, + "immed": true, + "latedef": true, + "nonbsp": true, + "undef": true, + + "browser": true, "devel": true, "globals": { + "DEBUG": true }, "maxerr": 100000 } diff --git a/README b/README index b249e36..cfd0e8c 100644 --- a/README +++ b/README @@ -60,9 +60,6 @@ automated tests use: - auto_tests/lib/Asserts.js (Apache 2.0 License) - auto-tests/lib/JsTestDriver-1.3.3cjar (Apache 2.0 License -Linter uses: - - JSHint (modified MIT license; prevents evil) - excanvas: http://code.google.com/p/explorercanvas/ yui compressor: http://developer.yahoo.com/yui/compressor/ jsdoc toolkit: http://code.google.com/p/jsdoc-toolkit/ @@ -71,6 +68,4 @@ jquery: http://code.jquery.com/jquery-1.4.2.js Asserts.js: http://www.google.com/codesearch/p?#3tsINRJRCro/trunk/JsTestDriver/src/com/google/jstestdriver/javascript/Asserts.js JSTestDriver: http://code.google.com/p/js-test-driver/ -JSHint: jshint.com - dygraphs is available under the MIT license, included in LICENSE.txt. diff --git a/bower.json b/bower.json index 9cb1240..2b21425 100644 --- a/bower.json +++ b/bower.json @@ -26,7 +26,6 @@ "gwt", "jsTestDriver.conf", "jsdoc-toolkit", - "jshint", "lint.sh", "node_modules", "package.json", diff --git a/dashed-canvas.js b/dashed-canvas.js index c92a322..0fc6874 100644 --- a/dashed-canvas.js +++ b/dashed-canvas.js @@ -4,6 +4,9 @@ * MIT-licensed (http://opensource.org/licenses/MIT) */ +(function() { +'use strict'; + /** * @fileoverview Adds support for dashed lines to the HTML5 canvas. * @@ -46,8 +49,6 @@ * as a smaller even length array. */ CanvasRenderingContext2D.prototype.installPattern = function(pattern) { - "use strict"; - if (typeof(this.isPatternInstalled) !== 'undefined') { throw "Must un-install old line pattern before installing a new one."; } @@ -175,3 +176,5 @@ CanvasRenderingContext2D.prototype.uninstallPattern = function() { // This will be replaced by a non-error version when a pattern is installed. throw "Must install a line pattern before uninstalling it."; }; + +})(); diff --git a/docs/legal.html b/docs/legal.html index 6b99843..c223f04 100644 --- a/docs/legal.html +++ b/docs/legal.html @@ -17,9 +17,6 @@ automated tests use: - auto_tests/lib/Asserts.js (Apache 2.0 License) - auto-tests/lib/JsTestDriver-1.3.3cjar (Apache 2.0 License -Linter uses: - - JSHint (modified MIT license; prevents evil) - excanvas: http://code.google.com/p/explorercanvas/ yui compressor: http://developer.yahoo.com/yui/compressor/ jsdoc toolkit: http://code.google.com/p/jsdoc-toolkit/ @@ -27,8 +24,6 @@ jsdoc toolkit: http://code.google.com/p/jsdoc-toolkit/ jquery: http://code.jquery.com/jquery-1.4.2.js Asserts.js: http://www.google.com/codesearch/p?#3tsINRJRCro/trunk/JsTestDriver/src/com/google/jstestdriver/javascript/Asserts.js JSTestDriver: http://code.google.com/p/js-test-driver/ - -JSHint: jshint.com diff --git a/dygraph-canvas.js b/dygraph-canvas.js index fa12934..4d7a7dd 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -24,7 +24,7 @@ * @constructor */ -/*jshint globalstrict: true */ +var DygraphCanvasRenderer = (function() { /*global Dygraph:false */ "use strict"; @@ -637,7 +637,6 @@ DygraphCanvasRenderer._errorPlotter = function(e) { DygraphCanvasRenderer._fastCanvasProxy = function(context) { var pendingActions = []; // array of [type, x, y] tuples var lastRoundedX = null; - var extremeYs = null; // [minY, maxY] for lastRoundedX var LINE_TO = 1, MOVE_TO = 2; @@ -946,3 +945,7 @@ DygraphCanvasRenderer._fillPlotter = function(e) { ctx.fill(); } }; + +return DygraphCanvasRenderer; + +})(); diff --git a/dygraph-gviz.js b/dygraph-gviz.js index 988e0ac..d2d7a0d 100644 --- a/dygraph-gviz.js +++ b/dygraph-gviz.js @@ -17,7 +17,7 @@ * - http://dygraphs.com/tests/annotation-gviz.html */ -/*jshint globalstrict: true */ +(function() { /*global Dygraph:false */ "use strict"; @@ -80,3 +80,5 @@ Dygraph.GVizChart.prototype.getSelection = function() { return selection; }; + +})(); diff --git a/dygraph-layout.js b/dygraph-layout.js index bf3d7e0..ef1df91 100644 --- a/dygraph-layout.js +++ b/dygraph-layout.js @@ -9,7 +9,8 @@ * dygraphs. */ -/*jshint globalstrict: true */ +var DygraphLayout = (function() { + /*global Dygraph:false */ "use strict"; @@ -344,3 +345,7 @@ DygraphLayout.prototype.removeAllDatasets = function() { this.setPointsLengths = []; this.setPointsOffsets = []; }; + +return DygraphLayout; + +})(); diff --git a/dygraph-options-reference.js b/dygraph-options-reference.js index b88e720..df63605 100644 --- a/dygraph-options-reference.js +++ b/dygraph-options-reference.js @@ -4,9 +4,6 @@ * MIT-licensed (http://opensource.org/licenses/MIT) */ -/*jshint globalstrict: true */ -/*global Dygraph:false */ - // NOTE: in addition to parsing as JS, this snippet is expected to be valid // JSON. This assumption cannot be checked in JS, but it will be checked when // documentation is generated by the generate-documentation.py script. For the diff --git a/dygraph-options.js b/dygraph-options.js index 413b9ea..fd6876a 100644 --- a/dygraph-options.js +++ b/dygraph-options.js @@ -11,6 +11,7 @@ */ var DygraphOptions = (function() { +/*jshint strict:false */ // For "production" code, this gets set to false by uglifyjs. // Need to define it outside of "use strict", hence the nested IIFEs. @@ -18,6 +19,7 @@ if (typeof(DEBUG) === 'undefined') DEBUG=true; return (function() { +// TODO: remove this jshint directive & fix the warnings. /*jshint sub:true */ /*global Dygraph:false */ "use strict"; diff --git a/dygraph-tickers.js b/dygraph-tickers.js index f23c87a..654877b 100644 --- a/dygraph-tickers.js +++ b/dygraph-tickers.js @@ -58,8 +58,9 @@ * middle of the years. */ -/*jshint globalstrict:true, sub:true */ +/*jshint sub:true */ /*global Dygraph:false */ +(function() { "use strict"; /** @typedef {Array.<{v:number, label:string, label_v:(string|undefined)}>} */ @@ -285,7 +286,7 @@ Dygraph.TICK_PLACEMENT[Dygraph.CENTENNIAL] = {datefield: Dygraph.DATEFIELD_ * NOTE: this assumes that Dygraph.LOG_SCALE = 10. * @type {Array.} */ -Dygraph.PREFERRED_LOG_TICK_VALUES = function() { +Dygraph.PREFERRED_LOG_TICK_VALUES = (function() { var vals = []; for (var power = -39; power <= 39; power++) { var range = Math.pow(10, power); @@ -295,7 +296,7 @@ Dygraph.PREFERRED_LOG_TICK_VALUES = function() { } } return vals; -}(); +})(); /** * Determine the correct granularity of ticks on a date axis. @@ -437,3 +438,5 @@ if (Dygraph && Dygraph.DEFAULT_ATTRS['axes']['y']['ticker'] = Dygraph.numericTicks; Dygraph.DEFAULT_ATTRS['axes']['y2']['ticker'] = Dygraph.numericTicks; } + +})(); diff --git a/dygraph.js b/dygraph.js index 6b6bc0d..348ef6c 100644 --- a/dygraph.js +++ b/dygraph.js @@ -47,7 +47,6 @@ if (typeof(DEBUG) === 'undefined') DEBUG=true; var Dygraph = (function() { -/*jshint globalstrict: true */ /*global DygraphLayout:false, DygraphCanvasRenderer:false, DygraphOptions:false, G_vmlCanvasManager:false,ActiveXObject:false */ "use strict"; @@ -118,10 +117,8 @@ Dygraph.KMG2_SMALL_LABELS = [ 'm', 'u', 'n', 'p', 'f', 'a', 'z', 'y' ]; * and maxNumberWidth options. * @param {number} x The number to be formatted * @param {Dygraph} opts An options view - * @param {string} name The name of the point's data series - * @param {Dygraph} g The dygraph object */ -Dygraph.numberValueFormatter = function(x, opts, pt, g) { +Dygraph.numberValueFormatter = function(x, opts) { var sigFigs = opts('sigFigs'); if (sigFigs !== null) { @@ -192,8 +189,8 @@ Dygraph.numberValueFormatter = function(x, opts, pt, g) { * variant for use as an axisLabelFormatter. * @private */ -Dygraph.numberAxisLabelFormatter = function(x, granularity, opts, g) { - return Dygraph.numberValueFormatter(x, opts, g); +Dygraph.numberAxisLabelFormatter = function(x, granularity, opts) { + return Dygraph.numberValueFormatter(x, opts); }; /** @@ -555,6 +552,7 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { var handlers = pluginInstance.activate(this); for (var eventName in handlers) { + if (!handlers.hasOwnProperty(eventName)) continue; // TODO(danvk): validate eventName. pluginDict.events[eventName] = handlers[eventName]; } @@ -3555,6 +3553,7 @@ Dygraph.prototype.updateOptions = function(input_attrs, block_redraw) { Dygraph.mapLegacyOptions_ = function(attrs) { var my_attrs = {}; for (var k in attrs) { + if (!attrs.hasOwnProperty(k)) continue; if (k == 'file') continue; if (attrs.hasOwnProperty(k)) my_attrs[k] = attrs[k]; } diff --git a/plugins/legend.js b/plugins/legend.js index c88727a..9a9b9fe 100644 --- a/plugins/legend.js +++ b/plugins/legend.js @@ -7,17 +7,14 @@ Dygraph.Plugins.Legend = (function() { /* - Current bits of jankiness: - Uses two private APIs: 1. Dygraph.optionsViewForAxis_ 2. dygraph.plotter_.area - Registers for a "predraw" event, which should be renamed. - I call calculateEmWidthInDiv more often than needed. - */ -/*jshint globalstrict: true */ /*global Dygraph:false */ "use strict"; diff --git a/plugins/range-selector.js b/plugins/range-selector.js index af9e679..399ed39 100644 --- a/plugins/range-selector.js +++ b/plugins/range-selector.js @@ -12,7 +12,6 @@ Dygraph.Plugins.RangeSelector = (function() { -/*jshint globalstrict: true */ /*global Dygraph:false */ "use strict";