From ee28ebb16c952e028572308cbf93028904863b7b Mon Sep 17 00:00:00 2001 From: Luis Leiva Date: Sun, 26 May 2019 20:32:41 +0300 Subject: [PATCH] Linted code --- .eslintrc.js | 2 ++ jquery.sketchable.animate.js | 6 ++-- jquery.sketchable.js | 24 ++++++------- jquery.sketchable.serializer.js | 5 +-- jsdoc.json | 2 ++ jsketch.js | 60 ++++++++++++++++----------------- package.json | 4 +-- sketchable.animate.js | 4 +-- sketchable.js | 6 ++-- sketchable.serializer.js | 3 +- sketchable.svg.js | 2 +- 11 files changed, 62 insertions(+), 56 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index ed31d1c..dd5f7fb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -14,6 +14,8 @@ module.exports = { 'no-multi-spaces': 0, 'object-curly-spacing': 0, 'require-jsdoc': 0, + 'prefer-spread': 0, + 'no-multi-str': 0, // --- BEGIN Errors --- 'no-tabs': 2, 'indent': ['error', 2], diff --git a/jquery.sketchable.animate.js b/jquery.sketchable.animate.js index 871de49..bec841d 100644 --- a/jquery.sketchable.animate.js +++ b/jquery.sketchable.animate.js @@ -64,7 +64,7 @@ /** * Cancel current animation. - * @return {AnimateSketch}. + * @return {AnimateSketch} */ this.cancel = function() { cancelAnimationFrame(raf); @@ -87,8 +87,8 @@ if (sketch.data.firstPointSize) { var pt = t > 0 ? nextPt : currPt; sketch.beginFill(sketch.data.strokeStyle) - .fillCircle(pt.x, pt.y, sketch.data.firstPointSize) - .endFill(); + .fillCircle(pt.x, pt.y, sketch.data.firstPointSize) + .endFill(); } // Trigger step event for subsequent strokes. if (t > 0 && typeof events.animationstep === 'function') diff --git a/jquery.sketchable.js b/jquery.sketchable.js index 2979e7e..5e2ebc5 100644 --- a/jquery.sketchable.js +++ b/jquery.sketchable.js @@ -26,7 +26,7 @@ /** * Initialize the selected jQuery objects. * @param {object} [opts] - Configuration (default: {@link $.fn.sketchable.defaults}). - * @return jQuery + * @return {object} jQuery * @memberof $.fn.sketchable * @ignore * @protected @@ -76,7 +76,7 @@ /** * Change configuration of an existing jQuery Sketchable element. * @param {object} [opts] - Configuration (default: {@link $.fn.sketchable.defaults}). - * @return jQuery + * @return {object} jQuery * @memberof $.fn.sketchable * @example * var $canvas = $('canvas').sketchable('config', { interactive: false }); @@ -97,7 +97,7 @@ /** * Get/Set drawing data strokes sequence. * @param {array} [arr] - Multidimensional array of [x,y,time,status] tuples; status = 0 (pen down) or 1 (pen up). - * @return Strokes object on get, jQuery instance on set (with the new data attached). + * @return {*} Strokes object on get, jQuery instance on set (with the new data attached). * @memberof $.fn.sketchable * @example * // Getter: read associated strokes. @@ -119,7 +119,7 @@ /** * Allow low-level manipulation of the sketchable canvas. * @param {function} callback - Callback function, invoked with 2 arguments: elem (CANVAS element) and data (private element data). - * @return jQuery + * @return {object} jQuery * @memberof $.fn.sketchable * @example * $('canvas').sketchable('handler', function(elem, data) { @@ -134,7 +134,7 @@ }, /** * Clears canvas together with associated strokes data. - * @return jQuery + * @return {object} jQuery * @memberof $.fn.sketchable * @see $.fn.sketchable.handler * @example @@ -162,7 +162,7 @@ /** * Reinitialize a sketchable canvas with given configuration options. * @param {object} [opts] - Configuration (default: {@link $.fn.sketchable.defaults}). - * @return jQuery + * @return {object} jQuery * @memberof $.fn.sketchable * @example * var $canvas = $('canvas').sketchable(); @@ -183,7 +183,7 @@ }, /** * Destroy sketchable canvas, together with strokes data and associated events. - * @return jQuery + * @return {object} jQuery * @memberof $.fn.sketchable * @example * var $canvas = $('canvas').sketchable(); @@ -212,7 +212,7 @@ * @param {string} evName - Event name. * @param {function} listener - Custom event listener. * @param {string} initiator - Some identifier. - * @return jQuery + * @return {object} jQuery * @memberof $.fn.sketchable * @example * // Decorate 'clear' method with `myClearFn()`, @@ -247,7 +247,7 @@ * This is a jQuery wrapper for the jSketch drawing class. * @namespace $.fn.sketchable * @param {string|object} method - Method to invoke, or a configuration object. - * @return jQuery + * @return {object} jQuery * @version 2.2 * @author Luis A. Leiva * @license MIT license @@ -517,9 +517,9 @@ // Mark visually 1st point of stroke. if (options.graphics.firstPointSize > 0) { data.sketch - .beginFill(options.graphics.fillStyle) - .fillCircle(p.x, p.y, options.graphics.firstPointSize) - .endFill(); + .beginFill(options.graphics.fillStyle) + .fillCircle(p.x, p.y, options.graphics.firstPointSize) + .endFill(); } data.sketch.isDrawing = true; diff --git a/jquery.sketchable.serializer.js b/jquery.sketchable.serializer.js index bdcdc72..5af927e 100644 --- a/jquery.sketchable.serializer.js +++ b/jquery.sketchable.serializer.js @@ -23,12 +23,12 @@ serializer: { /** * Save canvas data as JSON string. - * @return {string} serialized canvas data. + * @return {string} * @memberof $.fn.sketchable.plugins.serializer * @example * var contents = jqueryElem.sketchable('serializer.save'); */ - save: function(contents) { + save: function() { var data = $(this).data(namespace); // Save only the required properties. // Also avoid circular JSON references. @@ -40,6 +40,7 @@ }, /** * Load canvas data from JSON string. + * @param {string} jsonStr - JSON data saved with {@link $.fn.sketchable.plugins.serializer.save} method. * @return {jQuery} jQuery sketchable element. * @memberof $.fn.sketchable.plugins.serializer * @example diff --git a/jsdoc.json b/jsdoc.json index ed717ba..42b76ee 100644 --- a/jsdoc.json +++ b/jsdoc.json @@ -7,10 +7,12 @@ "sketchable.utils.js", "sketchable.memento.js", "sketchable.animate.js", + "sketchable.serializer.js", "sketchable.svg.js", "jquery.sketchable.js", "jquery.sketchable.memento.js", "jquery.sketchable.animate.js", + "jquery.sketchable.serializer.js", "jquery.sketchable.svg.js" ] }, diff --git a/jsketch.js b/jsketch.js index 85b581d..f6de377 100644 --- a/jsketch.js +++ b/jsketch.js @@ -52,7 +52,7 @@ /** * Allows to change the drawing context at runtime. * @param {object} elem - DOM element. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ setContext: function(elem) { @@ -71,7 +71,7 @@ * - lineCap: Line cap ('round'). * - lineJoin: Line join ('round'). * - miterLimit: Line miter (10). Works only if the lineJoin attribute is "miter". - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ setDefaults: function() { @@ -94,7 +94,7 @@ * Sets the dimensions of canvas. * @param {number} width - New canvas width. * @param {number} height - New canvas width. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ size: function(width, height) { @@ -109,7 +109,7 @@ /** * Sets the background color of canvas. * @param {string} color - An HTML color. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ background: function(color) { @@ -128,7 +128,7 @@ * @param {number} width - New canvas width. * @param {number} height - New canvas width. * @param {string} bgcolor - An HTML color. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ stage: function(width, height, bgcolor) { @@ -138,7 +138,7 @@ /** * Sets the fill color. * @param {string} color - An HTML color. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ beginFill: function(color) { @@ -149,7 +149,7 @@ }, /** * Recovers the fill color that was set before `beginFill()`. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ endFill: function() { @@ -163,7 +163,7 @@ * @param {string} capStyle - Style of line cap. * @param {string} joinStyle - Style of line join. * @param {string} miter - Style of line miter. Only works if capStyle is "miter". - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ lineStyle: function(color, thickness, capStyle, joinStyle, miter) { @@ -180,7 +180,7 @@ * Move brush to a coordinate in canvas. * @param {number} x - Horizontal coordinate. * @param {number} y - Vertical coordinate. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ moveTo: function(x, y) { @@ -193,7 +193,7 @@ * Draws line to given coordinate. * @param {number} x - Horizontal coordinate. * @param {number} y - Vertical coordinate. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ lineTo: function(x, y) { @@ -208,7 +208,7 @@ * @param {number} y1 - Vertical coordinate of point 1. * @param {number} x2 - Horizontal coordinate of point 2. * @param {number} y2 - Vertical coordinate of point 2. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ line: function(x1, y1, x2, y2) { @@ -222,7 +222,7 @@ * @param {number} y - Vertical coordinate. * @param {number} cpx - Horizontal coordinate of control point. * @param {number} cpy - Vertical coordinate of control point. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ curveTo: function(x, y, cpx, cpy) { @@ -240,7 +240,7 @@ * @param {number} y2 - Vertical coordinate of point 2. * @param {number} cpx - Horizontal coordinate of control point. * @param {number} cpy - Vertical coordinate of control point. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ curve: function(x1, y1, x2, y2, cpx, cpy) { @@ -250,7 +250,7 @@ }, /** * Strokes a given path. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ stroke: function() { @@ -264,7 +264,7 @@ * @param {number} y - Vertical coordinate. * @param {number} width - Rectangle width. * @param {number} height - Rectangle height. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ strokeRect: function(x, y, width, height) { @@ -284,7 +284,7 @@ * @param {number} y - Vertical coordinate. * @param {number} width - Rectangle width. * @param {number} height - Rectangle height. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ fillRect: function(x, y, width, height) { @@ -304,7 +304,7 @@ * @param {number} y - Vertical coordinate. * @param {number} width - Rectangle width. * @param {number} height - Rectangle height. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ rect: function(x, y, width, height) { @@ -318,7 +318,7 @@ * @param {number} x - Horizontal coordinate. * @param {number} y - Vertical coordinate. * @param {number} radius - Circle radius. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ strokeCircle: function(x, y, radius) { @@ -338,7 +338,7 @@ * @param {number} x - Horizontal coordinate. * @param {number} y - Vertical coordinate. * @param {number} radius - Circle radius. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ fillCircle: function(x, y, radius) { @@ -358,7 +358,7 @@ * @param {number} x - Horizontal coordinate. * @param {number} y - Vertical coordinate. * @param {number} radius - Circle radius. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ circle: function(x, y, radius) { @@ -386,7 +386,7 @@ }, /** * A path is started. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ beginPath: function() { @@ -397,7 +397,7 @@ }, /** * A path is finished. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ closePath: function() { @@ -408,7 +408,7 @@ }, /** * Sets brush to eraser mode. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ eraser: function() { @@ -418,7 +418,7 @@ }, /** * Sets brush to pencil mode. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ pencil: function() { @@ -428,7 +428,7 @@ }, /** * Clears stage. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ clear: function() { @@ -440,7 +440,7 @@ }, /** * Saves a snapshot of all styles and transformations. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ save: function() { @@ -450,7 +450,7 @@ }, /** * Restores previous drawing state. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ restore: function() { @@ -461,7 +461,7 @@ /** * Saves given drawing settings. * @param {object} [options] - Graphics options. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ saveGraphics: function(options) { @@ -477,7 +477,7 @@ }, /** * Restores given drawing settings. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ restoreGraphics: function() { @@ -491,7 +491,7 @@ * @param {string} src - Image source path. * @param {number} [x] - Horizontal coordinate. * @param {number} [y] - Vertical coordinate. - * @return jSketch + * @return {object} jSketch * @memberof jSketch */ drawImage: function(src, x, y) { diff --git a/package.json b/package.json index c50c273..a450768 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "jsketch", - "version": "2.0.0", + "version": "2.0.1", "description": "jSketch drawing lib", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "dist": "grunt", - "lint": "eslint *sketchable*.js || echo [sudo] npm i -g eslint", + "lint": "eslint *sketch*.js || echo [sudo] npm i -g eslint", "docs": "jsdoc --debug -c jsdoc.json && cp -rn figs/ docs/ || echo [sudo] npm i -g jsdoc" }, "repository": { diff --git a/sketchable.animate.js b/sketchable.animate.js index d7785e1..c8bea41 100644 --- a/sketchable.animate.js +++ b/sketchable.animate.js @@ -89,8 +89,8 @@ if (sketch.data.firstPointSize) { var pt = t > 0 ? nextPt : currPt; sketch.beginFill(sketch.data.strokeStyle) - .fillCircle(pt.x, pt.y, sketch.data.firstPointSize) - .endFill(); + .fillCircle(pt.x, pt.y, sketch.data.firstPointSize) + .endFill(); } // Trigger step event for subsequent strokes. if (t > 0 && typeof events.animationstep === 'function') diff --git a/sketchable.js b/sketchable.js index 4ae8130..50c7227 100644 --- a/sketchable.js +++ b/sketchable.js @@ -517,9 +517,9 @@ // Mark visually 1st point of stroke. if (options.graphics.firstPointSize > 0) { data.sketch - .beginFill(options.graphics.fillStyle) - .fillCircle(p.x, p.y, options.graphics.firstPointSize) - .endFill(); + .beginFill(options.graphics.fillStyle) + .fillCircle(p.x, p.y, options.graphics.firstPointSize) + .endFill(); } data.sketch.isDrawing = true; diff --git a/sketchable.serializer.js b/sketchable.serializer.js index 5876f56..5cb9289 100644 --- a/sketchable.serializer.js +++ b/sketchable.serializer.js @@ -25,7 +25,7 @@ serializer: { /** * Save canvas data as JSON string. - * @return {string} serialized canvas data. + * @return {string} Serialized canvas data. * @memberof Sketchable.plugins.serializer * @example * var contents = sketchableInstance.serializer.save(); @@ -42,6 +42,7 @@ }, /** * Load canvas from JSON string. + * @param {string} jsonStr - JSON data saved with {@link Sketchable.plugins.serializer.save} method. * @return {Sketchable} Sketchable element. * @memberof Sketchable.plugins.serializer * @example diff --git a/sketchable.svg.js b/sketchable.svg.js index 369e031..85e25a1 100644 --- a/sketchable.svg.js +++ b/sketchable.svg.js @@ -40,7 +40,7 @@ deepExtend(instance, { // Namespace methods to avoid collisions with other plugins. svg: { - /** + /** * Generate SVG. * @param {function} callback - Callback function, executed with the SVG (string) as argument. * @return {Sketchable} Sketchable element.