From fa4ea90c72e8a573abcad630cd2d30c349a3805c Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Fri, 24 May 2019 14:44:57 +0800 Subject: [PATCH] INCOMPLETE: Remove check types file - Linting: `match-description`, bad returns - Linting: Use eslint-plugin-jdsoc `preferredTypes` in place of custom file - Linting: Remove `report-unused-disable-directives` command as have as rule - Lintin: Avoid overly generic `Array` - npm: Update devDep --- .eslintrc.js | 34 +++++++++++++++++-- editor/canvg/canvg.js | 2 ++ editor/extensions/ext-placemark.js | 2 +- .../dynamic-import-polyfill/importModule.js | 4 +++ editor/svg-editor.js | 8 ++--- editor/svgtransformlist.js | 3 +- package-lock.json | 20 +++++------ package.json | 4 +-- test/path_test.js | 8 ++++- 9 files changed, 64 insertions(+), 21 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index cc365c75..cdb26d85 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -65,6 +65,32 @@ module.exports = { } } */ + forceRequireReturn: true, + // Todo: Once PR to eslint-plugin-jsdoc may be merged, fix its "reenable later" to-dos for `jsdoc/check-types` in canvg.js file + preferredTypes: { + "*": { + message: "Use a more precise type or if necessary use `{{preferredType}}` or `ArbitraryCallbackResult`", + replacement: "Any" + }, + any: { + message: "Use a more precise type or if necessary use `{{preferredType}}` or `ArbitraryCallbackResult`", + replacement: "Any" + }, + number: { + message: "Use `Integer` or `Float`" + }, + Function: { + message: "Point to a `@callback` namepath or `GenericCallback` if truly arbitrary in form" + }, + 'object<>': { + message: "Use the specific object type or `{{preferredType}}` (or `ArbitraryObject` or `ArbitraryModule`) if truly arbitrary", + replacement: "PlainObject" + }, + 'Array<>': { + message: "Use `{{preferredType}}` (or `ArgumentsArray`) if it is truly arbitrary.", + replacement: "GenericArray" + } + } } }, overrides: [ @@ -189,7 +215,11 @@ module.exports = { "unicorn/prefer-query-selector": "off", "unicorn/prefer-node-append": "off", "unicorn/no-zero-fractions": "off", - // Disable until ash-nazg removes - "valid-jsdoc": "off" + + // Remove when ash-nazg removes + "valid-jsdoc": "off", + // Remove when ash-nazg adds + "jsdoc/require-returns-check": ["error"], + "jsdoc/match-description": ["error"], } }; diff --git a/editor/canvg/canvg.js b/editor/canvg/canvg.js index 6ba09708..8710d1eb 100644 --- a/editor/canvg/canvg.js +++ b/editor/canvg/canvg.js @@ -90,12 +90,14 @@ export const canvg = function (target, s, opts) { return svg.load(ctx, s); }; +/* Todo: Reenable after ash-nazg may merge; eslint-disable jsdoc/check-types */ /** * @param {module:canvg.CanvgOptions} opts * @returns {object} * @todo Flesh out exactly what object is returned here (after updating to latest and reincluding our changes here and those of StackBlur) */ function build (opts) { + /* Todo: Reenable after ash-nazg may merge; eslint-enable jsdoc/check-types */ const svg = {opts}; svg.FRAMERATE = 30; diff --git a/editor/extensions/ext-placemark.js b/editor/extensions/ext-placemark.js index f6099126..8aa53566 100644 --- a/editor/extensions/ext-placemark.js +++ b/editor/extensions/ext-placemark.js @@ -240,7 +240,7 @@ export default { } /** * @param {Event} ev - * @returns {Promise} Resolves to `undefined` + * @returns {void} */ function setArrowFromButton (ev) { const parts = this.id.split('_'); diff --git a/editor/external/dynamic-import-polyfill/importModule.js b/editor/external/dynamic-import-polyfill/importModule.js index 8f5ab0e9..e6fd1196 100644 --- a/editor/external/dynamic-import-polyfill/importModule.js +++ b/editor/external/dynamic-import-polyfill/importModule.js @@ -36,6 +36,7 @@ function addScriptAtts (script, atts) { * @property {string} global The variable name to set on `window` (when not using the modular version) * @property {boolean} [returnDefault=false] */ +/* eslint-disable jsdoc/check-types */ /** * @function module:importModule.importSetGlobalDefault * @param {string|string[]} url @@ -43,6 +44,7 @@ function addScriptAtts (script, atts) { * @returns {Promise<*>} The value to which it resolves depends on the export of the targeted module. */ export function importSetGlobalDefault (url, config) { + /* eslint-enable jsdoc/check-types */ return importSetGlobal(url, {...config, returnDefault: true}); } /** @@ -111,6 +113,7 @@ export function importScript (url, atts = {}) { }); } +/* eslint-disable jsdoc/check-types */ /** * * @param {string|string[]} url @@ -121,6 +124,7 @@ export function importScript (url, atts = {}) { * `Error` upon a script loading error. */ export function importModule (url, atts = {}, {returnDefault = false} = {}) { + /* eslint-enable jsdoc/check-types */ if (Array.isArray(url)) { return Promise.all(url.map((u) => { return importModule(u, atts); diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 800bde54..b514f78a 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -1174,7 +1174,7 @@ editor.init = function () { }; /** - * Setup SVG icons + * Setup SVG icons. * @returns {void} */ function setIcons () { @@ -1551,7 +1551,7 @@ editor.init = function () { /** * This function highlights the layer passed in (by fading out the other layers). - * If no layer is passed in, this function restores the other layers + * If no layer is passed in, this function restores the other layers. * @param {string} [layerNameToHighlight] * @returns {void} */ @@ -5961,7 +5961,7 @@ editor.init = function () { ); /** - * Implements {@see module:jQueryContextMenu.jQueryContextMenuListener} + * Implements {@see module:jQueryContextMenu.jQueryContextMenuListener}. * @param {"dupe"|"delete"|"merge_down"|"merge_all"} action * @param {external:jQuery} el * @param {{x: Float, y: Float, docX: Float, docY: Float}} pos @@ -6146,7 +6146,7 @@ editor.init = function () { reader = new FileReader(); reader.onloadend = function ({target: {result}}) { /** - * Insert the new image until we know its dimensions + * Insert the new image until we know its dimensions. * @param {Float} width * @param {Float} height * @returns {void} diff --git a/editor/svgtransformlist.js b/editor/svgtransformlist.js index d99c549d..055475bd 100644 --- a/editor/svgtransformlist.js +++ b/editor/svgtransformlist.js @@ -123,6 +123,7 @@ let listMap_ = {}; export class SVGTransformList { // eslint-disable-line no-shadow /** * @param {Element} elem + * @returns {SVGTransformList} */ constructor (elem) { this._elem = elem || null; @@ -208,7 +209,7 @@ export class SVGTransformList { // eslint-disable-line no-shadow /** * @param {SVGTransform} newItem - * @returns {SVGTransform} + * @returns {void} */ initialize (newItem) { this.numberOfItems = 1; diff --git a/package-lock.json b/package-lock.json index 6b55e0cb..ec03758f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4263,9 +4263,9 @@ } }, "eslint-plugin-node": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-9.0.1.tgz", - "integrity": "sha512-fljT5Uyy3lkJzuqhxrYanLSsvaILs9I7CmQ31atTtZ0DoIzRbbvInBh4cQ1CrthFHInHYBQxfPmPt6KLHXNXdw==", + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-9.1.0.tgz", + "integrity": "sha512-ZwQYGm6EoV2cfLpE1wxJWsfnKUIXfM/KM09/TlorkukgCAwmkgajEJnPCmyzoFPQQkmvo5DrW/nyKutNIw36Mw==", "dev": true, "requires": { "eslint-plugin-es": "^1.4.0", @@ -4273,7 +4273,7 @@ "ignore": "^5.1.1", "minimatch": "^3.0.4", "resolve": "^1.10.1", - "semver": "^6.0.0" + "semver": "^6.1.0" }, "dependencies": { "ignore": { @@ -4283,18 +4283,18 @@ "dev": true }, "resolve": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.1.tgz", - "integrity": "sha512-KuIe4mf++td/eFb6wkaPbMDnP6kObCaEtIDuHOUED6MNUo4K670KZUHuuvYPZDxNF0WVLw49n06M2m2dXphEzA==", + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.0.tgz", + "integrity": "sha512-WL2pBDjqT6pGUNSUzMw00o4T7If+z4H2x3Gz893WoUQ5KW8Vr9txp00ykiP16VBaZF5+j/OcXJHZ9+PCvdiDKw==", "dev": true, "requires": { "path-parse": "^1.0.6" } }, "semver": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.0.0.tgz", - "integrity": "sha512-0UewU+9rFapKFnlbirLi3byoOuhrSsli/z/ihNnvM24vgF+8sNBiI1LZPBSH9wJKUwaUbw+s3hToDLCXkrghrQ==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.1.0.tgz", + "integrity": "sha512-kCqEOOHoBcFs/2Ccuk4Xarm/KiWRSLEX9CAZF8xkJ6ZPlIoTZ8V5f7J16vYLJqDbR7KrxTJpR2lqjIEm2Qx9cQ==", "dev": true } } diff --git a/package.json b/package.json index 36c74bc1..b6b9991c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "compress-images": "imageoptim 'chrome-app/*.png' && imageoptim 'editor/extensions/*.png' && imageoptim 'editor/spinbtn/*.png' && imageoptim 'editor/jgraduate/images/*.{png,gif}' && imageoptim 'editor/images/*.png'", "copy": "cp node_modules/load-stylesheets/dist/index-es.js editor/external/load-stylesheets/index-es.js && cp node_modules/jamilih/dist/jml-es.js editor/external/jamilih/jml-es.js && cp node_modules/query-result/esm/index.js editor/external/query-result/esm/index.js && cp node_modules/qr-manipulation/dist/index-es.js editor/external/qr-manipulation/dist/index-es.js && cp node_modules/stackblur-canvas/dist/stackblur-es.js editor/external/stackblur-canvas/dist/stackblur-es.js && cp node_modules/regenerator-runtime/runtime.js editor/external/regenerator-runtime/runtime.js && cp node_modules/core-js-bundle/minified.js editor/external/core-js-bundle/minified.js", "remark": "remark -q -f .", - "eslint": "eslint --report-unused-disable-directives --ext js,md .", + "eslint": "eslint --ext js,md .", "rollup": "rollup -c", "start-embedded": "echo \"Open file to http://localhost:8000/editor/embedapi.html\" && static -p 8000 | static -p 8001 -H '{\"Access-Control-Allow-Origin\": \"*\"}'", "start": "echo \"Open file to http://localhost:8000/test/all_tests.html\" && static -p 8000", @@ -94,7 +94,7 @@ "eslint-plugin-jsdoc": "^6.0.3", "eslint-plugin-markdown": "^1.0.0", "eslint-plugin-no-use-extend-native": "^0.4.0", - "eslint-plugin-node": "9.0.1", + "eslint-plugin-node": "9.1.0", "eslint-plugin-promise": "4.1.1", "eslint-plugin-qunit": "^4.0.0", "eslint-plugin-standard": "4.0.0", diff --git a/test/path_test.js b/test/path_test.js index 3668aeff..e53f82cf 100644 --- a/test/path_test.js +++ b/test/path_test.js @@ -12,9 +12,15 @@ QUnit.log((details) => { } }); +/** +* @typedef {GenericArray} EditorContexts +* @property {module:path.EditorContext} 0 +* @property {module:path.EditorContext} 1 +*/ + /** * @param {SVGSVGElement} [svg] -* @returns {Array} +* @returns {EditorContexts} */ function getMockContexts (svg) { svg = svg || document.createElementNS(NS.SVG, 'svg');