diff --git a/.eslintignore b/.eslintignore index 3fccb3c3..53b84696 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,15 +1,10 @@ node_modules -ignore - coverage instrumented dist -docs/jsdoc archive -jsconfig.json mochawesome-report -releases !.eslintrc.js !.ncurc.js @@ -21,11 +16,6 @@ svgedit-custom.css # Vendor/minified files src/editor/jquery.min.js -src/editor/jspdf/jspdf.min.js -src/editor/jspdf/underscore-min.js - src/editor/extensions/ext-mathjax/mathjax -# jquery files -src/editor/jgraduate/jQuery.jPicker.js diff --git a/.eslintrc.js b/.eslintrc.js index 91e39b60..5792cfa8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -8,7 +8,8 @@ module.exports = { "plugin:promise/recommended", "plugin:import/errors", "plugin:markdown/recommended", - "plugin:sonarjs/recommended" + "plugin:sonarjs/recommended", + "eslint:recommended" ], plugins: ["jsdoc", "promise", "html", "import", "sonarjs"], parserOptions: { @@ -19,262 +20,47 @@ module.exports = { browser: true, es6: true }, - settings: { - polyfills: [ - // These are the primary polyfills needed by regular users if - // not present, e.g., with core-js-bundle; also those under - // extensions - "fetch", - "Promise", - "Promise.all", - // 'Set', - "Uint8Array", - "URL" - ] - }, rules: { - // check-examples is not picking up eslint config properly in some - // environments; see also discussion above - // `mocha-cleanup/no-assertions-outside-it` - "sonarjs/cognitive-complexity": 0, - "sonarjs/no-duplicate-string": 0, - "sonarjs/no-collapsible-if": 0, - "sonarjs/no-small-switch": 0, - "sonarjs/no-identical-functions": 0, - "sonarjs/no-duplicated-branches": 0, - - "jsdoc/check-examples": [ - "warn", - { - rejectExampleCodeRegex: "^`", - checkDefaults: true, - checkParams: true, - checkProperties: true - } - ], - // The Babel transform seems to have a problem converting these - "prefer-named-capture-group": "off", - "jsdoc/require-file-overview": [ - "error", - { - tags: { - file: { - initialCommentsOnly: true, - preventDuplicates: true - }, - license: { - initialCommentsOnly: true, - preventDuplicates: true - }, - copyright: { - initialCommentsOnly: true, - preventDuplicates: true - }, - author: { - initialCommentsOnly: true, - preventDuplicates: true - }, - module: { - initialCommentsOnly: true, - preventDuplicates: true - }, - exports: { - initialCommentsOnly: true, - preventDuplicates: true - } - } - } - ], - // Warning or Off for now but should be reviewed - // Override these rules which are difficult for us - // to apply at this time - "default-case": "off", - "require-unicode-regexp": "off", - "max-len": ["warn", { ignoreComments: true, code: 130 }], // 130 is too much but too many occurences - "eslint-comments/require-description": "off", - "compat/compat": "error", - "consistent-this": "off", - "import/no-anonymous-default-export": "off", - "node/no-unsupported-features/node-builtins": "warn", - "prefer-exponentiation-operator": "warn", - "node/no-unsupported-features/es-syntax": "off", - "no-unsanitized/method": [ - "error", - { - escape: { - methods: ["encodeURIComponent", "encodeURI"] - } - } - ] + "node/no-unsupported-features/es-syntax": 0, + "no-unused-vars": ["error", { "argsIgnorePattern": "^_" }], + "sonarjs/cognitive-complexity": ["warn", 40], + "sonarjs/no-duplicate-string": 0, }, overrides: [ - // Locales have no need for importing outside of SVG-Edit - // and translations may need a longer line length { - files: [ - 'src/editor/locale/lang.*.js', - 'src/editor/extensions/*/locale/**', - 'docs/tutorials/ExtensionDocs.md/*.js' - ], - rules: { - "import/no-anonymous-default-export": "off", - "max-len": "off", - "node/no-missing-import": "off", - "import/no-unresolved": "off" - } - }, - // These browser files don't do importing or requiring - { - files: [ - "src/editor/touch.js", - "src/editor/typedefs.js", - "src/editor/redirect-on-no-module-support.js", - "src/editor/extensions/ext-imagelib/index.js", - "screencasts/svgopen2010/script.js" - ], - rules: { - "import/unambiguous": ["off"] - } - }, - { - files: ["**/*.html", "screencasts/**"], - globals: { - root: "off" - }, - settings: { - polyfills: [ - "document.querySelector", - "history", - "history.pushState", - "history.replaceState", - "location.hash", - "navigator", - "Number.parseFloat", - "Number.parseInt", - "Number.isNaN" - ] - }, - rules: { - "import/unambiguous": "off" - } - }, - { - // As consumed by jsdoc, cannot be expressed as ESM - files: ["docs/jsdoc-config.js"], - parserOptions: { - sourceType: "script" - }, - globals: { - module: false - }, - rules: { - "import/no-commonjs": "off", - strict: "off" - } - }, - { - files: ["cypress/**"], - extends: [ - "plugin:cypress/recommended", - "plugin:mocha/recommended", - "plugin:mocha-cleanup/recommended-no-limits", - "plugin:@fintechstudios/chai-as-promised/recommended", - "plugin:chai-expect-keywords/recommended", - "plugin:chai-expect/recommended", - "plugin:chai-friendly/recommended" + files: [ 'cypress/**/*'], + extends: [ + "plugin:cypress/recommended" ], env: { + mocha: true, node: true }, - settings: { - polyfills: [ - "console", - "Date.now", - "document.body", - "document.createElementNS", - "document.head", - "DOMParser", - "Number.isNaN", - "Object.keys", - "Object.entries", - "Promise" - ] + globals: { + "assert": true }, rules: { - // These errors are caused in Cypress files if user has not - // yet instrumented code; need to reinvestigate why we had to - // instrument separately from nyc mocha - "import/no-unresolved": ["error", { ignore: ["/instrumented/"] }], - "node/no-missing-import": "off", - "jsdoc/check-examples": "off", - "chai-expect-keywords/no-unsupported-keywords": [ - "error", - { - allowChaiDOM: true - } - ], - // Would be good but seems necessary due to some bugs in Cypress - // in detecting visibility - // 'cypress/no-force': 0, - // Good but would be difficult to enforce (and data-* may not be less - // brittle than IDs/classes anyways) - // 'cypress/require-data-selectors': 0, - "cypress/assertion-before-screenshot": 2, - - // Conflicts with Cypress `should` - "mocha-cleanup/invalid-assertions": 0, - - // Might see about working around to avoid the option limitation, - // but convenient - "mocha-cleanup/no-expressions-in-assertions": [ - "error", - { - replacementsOnly: true - } - ], - - // Too oppressive when planning to extend a section - "mocha/no-hooks-for-single-case": 0, - - // Would be good to enable but needs some refactoring - "mocha/no-setup-in-describe": 0, - "mocha-cleanup/no-outside-declaration": 0, - - // Useful to ensure allowing `this.timeout()`, etc., but a - // little oppressive - "mocha/no-mocha-arrows": 0, - // Useful if enabling the regular `prefer-arrow-callback` - // 'mocha/prefer-arrow-callback': 2 - - "jsdoc/require-jsdoc": 0, - "no-console": 0, - "import/unambiguous": 0 + // with ci, instrumented is not created before linter + "import/no-unresolved": [2, { ignore: ['instrumented'] }], + "node/no-missing-import": 0 } }, { - // Node files - files: [ - "docs/jsdoc-config.js", - "build/build-html.js", - "rollup.config.js", - "rollup-config.config.js" - ], - env: { - node: true - }, - settings: { - polyfills: ["console", "Promise.resolve"] - }, - globals: { - require: true - }, - rules: { - // We can't put Rollup in npmignore or user can't get access, - // and we have too many modules to add to `peerDependencies` - // so this rule can know them to be available, so we instead - // disable - "node/no-unpublished-import": "off" + files: [ 'docs/**/*'], + rules: { // md files have example that don't need a strict checking + "no-undef": 0, + "import/no-unresolved": 0, + "node/no-missing-import": 0, + "jsdoc/check-examples": [ + "warn", + { + rejectExampleCodeRegex: "^`", + checkDefaults: true, + checkParams: true, + checkProperties: true + } + ] } } ] -}; \ No newline at end of file +}; diff --git a/cypress/integration/ui/accessibility.js b/cypress/integration/ui/accessibility.js index 577ab542..5ee13042 100644 --- a/cypress/integration/ui/accessibility.js +++ b/cypress/integration/ui/accessibility.js @@ -8,7 +8,6 @@ describe('UI - Accessibility', function () { cy.injectAxe(); }); // https://www.npmjs.com/package/cypress-axe - // eslint-disable-next-line mocha/no-skipped-tests it.skip('Has no detectable a11y violations on load', () => { // Configure aXe and test the page at initial load cy.configureAxe({ diff --git a/cypress/integration/ui/control-points.js b/cypress/integration/ui/control-points.js index b1c52b5c..4f1fe7a3 100644 --- a/cypress/integration/ui/control-points.js +++ b/cypress/integration/ui/control-points.js @@ -20,7 +20,7 @@ describe('UI - Control Points', function () { `, {force: true, parseSpecialCharSequences: false}); cy.get('#tool_source_save').click({force: true}); - cy.get('#svg_1').click().click(); + cy.get('#svg_1').click({force: true}).click({force: true}); cy.get('#pathpointgrip_0').trigger('mousedown', {which: 1, force: true}) .trigger('mousemove', randomOffset(), randomOffset(), {force: true}) diff --git a/cypress/integration/ui/key-commands.js b/cypress/integration/ui/key-commands.js index aecb1e07..9c00fcc3 100644 --- a/cypress/integration/ui/key-commands.js +++ b/cypress/integration/ui/key-commands.js @@ -8,7 +8,6 @@ describe('Key commands', function () { visitAndApproveStorage(); }); - // eslint-disable-next-line mocha/no-skipped-tests it.skip('cmd-A on empty canvas should not cause an error', function () { cy.get('body').type('{cmd}a'); }); diff --git a/cypress/integration/unit/draw.js b/cypress/integration/unit/draw.js index 1ec90543..0bb610bf 100644 --- a/cypress/integration/unit/draw.js +++ b/cypress/integration/unit/draw.js @@ -44,7 +44,7 @@ describe('draw.Drawing', function () { const getCurrentDrawing = function () { return currentDrawing_; }; - const setCurrentGroup = (cg) => { /* empty fn */ }; + const setCurrentGroup = () => { /* empty fn */ }; draw.init( /** * @implements {module:draw.DrawCanvasInit} diff --git a/cypress/integration/unit/history.js b/cypress/integration/unit/history.js index aa84368c..11b00cd6 100644 --- a/cypress/integration/unit/history.js +++ b/cypress/integration/unit/history.js @@ -9,12 +9,12 @@ describe('history', function () { // TODO(codedread): Write tests for handling history events. // Mocked out methods. - transformlist.changeRemoveElementFromListMap((elem) => { /* empty fn */ }); + transformlist.changeRemoveElementFromListMap(() => { /* empty fn */ }); utilities.mock({ - getHref (elem) { return '#foo'; }, - setHref (elem, val) { /* empty fn */ }, - getRotationAngle (elem) { return 0; } + getHref () { return '#foo'; }, + setHref () { /* empty fn */ }, + getRotationAngle () { return 0; } }); // const svg = document.createElementNS(NS.SVG, 'svg'); @@ -452,7 +452,7 @@ describe('history', function () { assert.equal(val, sethrefvalue); justCalled = 'setHref'; }, - getRotationAngle (elem) { return 0; } + getRotationAngle () { return 0; } }); gethrefvalue = '#newhref'; @@ -488,7 +488,7 @@ describe('history', function () { it('Test BatchCommand', function () { let concatResult = ''; - MockCommand.prototype.apply = function (handler) { concatResult += this.text; }; + MockCommand.prototype.apply = function () { concatResult += this.text; }; const batch = new hstory.BatchCommand(); assert.ok(batch.unapply); diff --git a/cypress/integration/unit/utilities-bbox.js b/cypress/integration/unit/utilities-bbox.js index ac497500..c21108f0 100644 --- a/cypress/integration/unit/utilities-bbox.js +++ b/cypress/integration/unit/utilities-bbox.js @@ -55,7 +55,7 @@ describe('utilities bbox', function () { const type = seg.pathSegType; if (type === 1) { continue; } const pts = []; - ['', 1, 2].forEach(function (n, j) { + ['', 1, 2].forEach(function (n) { const x = seg['x' + n], y = seg['y' + n]; if (x !== undefined && y !== undefined) { const pt = math.transformPoint(x, y, m); diff --git a/cypress/integration/unit/utilities-performance.js b/cypress/integration/unit/utilities-performance.js index 4f8b40a9..ef683ec0 100644 --- a/cypress/integration/unit/utilities-performance.js +++ b/cypress/integration/unit/utilities-performance.js @@ -135,7 +135,7 @@ describe('utilities performance', function () { continue; } const pts = []; - ['', 1, 2].forEach(function (n, j) { + ['', 1, 2].forEach(function (n) { const x = seg['x' + n], y = seg['y' + n]; if (x !== undefined && y !== undefined) { diff --git a/cypress/integration/unit/utilities.js b/cypress/integration/unit/utilities.js index 06e6b659..e0190053 100644 --- a/cypress/integration/unit/utilities.js +++ b/cypress/integration/unit/utilities.js @@ -348,7 +348,7 @@ describe('utilities', function () { const elem = { tagName: 'something unknown', id: 'something-unknown', - getAttribute (attr) { return ''; }, + getAttribute () { return ''; }, parentNode: svgroot }; const path = convertToPath(elem, attrs, mockaddSVGElementFromJson, mockPathActions, mockClearSelection, mockAddToSelection, mockHistory, mockAddCommandToHistory); diff --git a/cypress/support/assertion-wrapper.js b/cypress/support/assertion-wrapper.js index e12248be..18670779 100644 --- a/cypress/support/assertion-wrapper.js +++ b/cypress/support/assertion-wrapper.js @@ -3,7 +3,7 @@ * @param {external:chai_utils} utils * @returns {void} */ -function setAssertionMethods (_chai, utils) { +function setAssertionMethods (_chai, _utils) { return (method) => { return (...args) => { const {result, message, actual, expected} = method(...args); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index c64ca1ef..0bbd68c7 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -32,7 +32,7 @@ Cypress.Commands.add( { prevSubject: true }, - (subject, snapshotOptions) => { + (subject, _snapshotOptions) => { let html = subject[0].outerHTML; for (const attribute of ngAttributes) { diff --git a/docs/tutorials/Events.md b/docs/tutorials/Events.md index 60e4eb2a..b0f3e42d 100644 --- a/docs/tutorials/Events.md +++ b/docs/tutorials/Events.md @@ -8,7 +8,7 @@ the SVG file differently: ### Example ```js svgEditor.setCustomHandlers({ - save (win, data) { + save (_win, _data) { // Save svg } }); diff --git a/docs/tutorials/ExtensionDocs.md b/docs/tutorials/ExtensionDocs.md index 2eab3549..9bdd182a 100644 --- a/docs/tutorials/ExtensionDocs.md +++ b/docs/tutorials/ExtensionDocs.md @@ -27,7 +27,7 @@ This is the general format for an extension: ```js export default { name: 'extensionname', - init (methods) { + init (_methods) { return extensionData; } }; @@ -83,7 +83,7 @@ export default { mouseDown () { // ... }, - mouseUp (opts) { + mouseUp (_opts) { // ... } }; diff --git a/package-lock.json b/package-lock.json index dbbe5db7..1ccf8cdd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -60,7 +60,7 @@ "eslint-plugin-eslint-comments": "3.2.0", "eslint-plugin-html": "^6.1.2", "eslint-plugin-import": "^2.22.1", - "eslint-plugin-jsdoc": "^32.3.2", + "eslint-plugin-jsdoc": "^32.3.3", "eslint-plugin-markdown": "^2.1.0", "eslint-plugin-mocha": "8.1.0", "eslint-plugin-mocha-cleanup": "1.9.1", @@ -10277,9 +10277,9 @@ } }, "node_modules/eslint-plugin-jsdoc": { - "version": "32.3.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-32.3.2.tgz", - "integrity": "sha512-kcdg0OvhI466KgMYXwxGvP6+m9J/sIBg0Jkn9eDU5lnM6RSVM27M9zKZim2XY6AUbbdqmkBPEP4ixvtBXRHktQ==", + "version": "32.3.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-32.3.3.tgz", + "integrity": "sha512-WxXohbMYlZvCt3r7MepwT++nTLsO4CPegWcm5toM4IGq3MBmYkG+Uf5yDa+n1MwPXLg+KbJqAsI19hmkVD7MPg==", "dev": true, "dependencies": { "comment-parser": "1.1.5", @@ -33395,9 +33395,9 @@ } }, "eslint-plugin-jsdoc": { - "version": "32.3.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-32.3.2.tgz", - "integrity": "sha512-kcdg0OvhI466KgMYXwxGvP6+m9J/sIBg0Jkn9eDU5lnM6RSVM27M9zKZim2XY6AUbbdqmkBPEP4ixvtBXRHktQ==", + "version": "32.3.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-32.3.3.tgz", + "integrity": "sha512-WxXohbMYlZvCt3r7MepwT++nTLsO4CPegWcm5toM4IGq3MBmYkG+Uf5yDa+n1MwPXLg+KbJqAsI19hmkVD7MPg==", "dev": true, "requires": { "comment-parser": "1.1.5", diff --git a/package.json b/package.json index 35b69092..886e9a60 100644 --- a/package.json +++ b/package.json @@ -15,14 +15,15 @@ "scripts": { "lint": "eslint --ext js,html,md .", "test": "run-s cypress:instrument cypress:test", + "cypress:instrument": "rimraf instrumented && cp-cli src instrumented && nyc instrument --compact=false src instrumented", "cypress:test": "start-server-and-test start http://localhost:8000/instrumented/editor/index.html cypress:run", + "cypress:run": "run-s -n -c cypress:run-no-badge report-summary-mocha-full", "build": "rollup -c", "build:watch": "rollup -c --watch", "start": "web-dev-server --node-resolve", "start:watch": "web-dev-server --node-resolve --watch", "cypress:open": "run-p start cypress:open-no-start", "cypress:open-no-start": "cypress open", - "cypress:instrument": "rimraf instrumented && cp-cli src instrumented && nyc instrument --compact=false src instrumented", "add-release": "git submodule add --depth=1 -b \"release-v$npm_config_release\" -- https://github.com/SVG-Edit/svgedit.git \"releases/svg-edit-$npm_config_release\"", "add-new-release": "cross-var npm run add-release --release=$npm_package_version && cross-var git config --file=.gitmodules submodule.releases/latest.branch \"release-v$npm_package_version\"", "remove-release": "git submodule deinit -f \"releases/svg-edit-$npm_config_release\" && rm -rf .git/modules/releases/svg-edit-$npm_config_release && git rm -f releases/svg-edit-$npm_config_release", @@ -60,7 +61,6 @@ "cypress:merge": "mochawesome-merge \"cypress/results/mochaw*.json\" > mochawesome.json && marge mochawesome.json && mbg --file ./mochawesome.json --badge_output badges/tests-badge.svg", "cypress:run-only": "rimraf \"cypress/results/mochaw*.json\" && rimraf \".nyc_output/*\" && cypress run -q", "cypress:run-no-badge": "run-s -c cypress:run-only cypress:merge", - "cypress:run": "run-s -n -c cypress:run-no-badge report-summary-mocha-full", "mochawesome-cli": "node tools/mochawesome-cli.js", "mochawesome-cli-dot": "npm run mochawesome-cli -- --dot", "report-no-mochawesome": "nyc report", @@ -102,8 +102,12 @@ "not IE < 12", "not Chrome < 75", "not FireFox < 68", - "not Safari < 10", - "not ios_saf < 10" + "not Safari < 11", + "not ios_saf < 10", + "not android < 5", + "not op_mini all", + "not Edge < 18", + "not dead" ], "dependencies": { "@babel/polyfill": "7.12.1", @@ -158,7 +162,7 @@ "eslint-plugin-eslint-comments": "3.2.0", "eslint-plugin-html": "^6.1.2", "eslint-plugin-import": "^2.22.1", - "eslint-plugin-jsdoc": "^32.3.2", + "eslint-plugin-jsdoc": "^32.3.3", "eslint-plugin-markdown": "^2.1.0", "eslint-plugin-mocha": "8.1.0", "eslint-plugin-mocha-cleanup": "1.9.1", diff --git a/rollup.config.js b/rollup.config.js index 7654fc32..c9bf767c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,3 +1,4 @@ +/* eslint-disable node/no-unpublished-import */ /* eslint-env node */ // This rollup script is run by the command: // 'npm run build' diff --git a/src/editor/Editor.js b/src/editor/Editor.js index a8236e17..8d72cc38 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -1,5 +1,5 @@ /* eslint-disable max-len */ -/* globals jQuery seConfirm seAlert */ +/* globals seConfirm seAlert $ */ /** * The main module for the visual SVG this. * @@ -19,8 +19,6 @@ import { isMac } from '../common/browser.js'; import SvgCanvas from '../svgcanvas/svgcanvas.js'; import ConfigObj from './ConfigObj.js'; -import {mergeDeep} from './components/jgraduate/Util.js'; - import EditorStartup from './EditorStartup.js'; import LeftPanel from './panels/LeftPanel.js'; import TopPanel from './panels/TopPanel.js'; @@ -29,7 +27,7 @@ import LayersPanel from './panels/LayersPanel.js'; import MainMenu from './MainMenu.js'; import { getParentsUntil } from './components/jgraduate/Util.js'; -const { $id, $qa, isNullish, encode64, decode64, blankPageObjectURL } = SvgCanvas; +const { $id, $qa, isNullish, decode64, blankPageObjectURL } = SvgCanvas; /** @@ -531,6 +529,7 @@ class Editor extends EditorStartup { this.workarea.scroll(); } + // eslint-disable-next-line sonarjs/no-collapsible-if if (this.configObj.urldata.storagePrompt !== true && this.storagePromptState === 'ignore') { if ($id("dialog_box") != null) $id("dialog_box").style.display = 'none'; } @@ -618,6 +617,7 @@ class Editor extends EditorStartup { this.multiselected = (elems.length >= 2 && !isNullish(elems[1])); // Only updating fields for single elements for now if (!this.multiselected) { + // eslint-disable-next-line sonarjs/no-small-switch switch (mode) { case 'rotate': { const ang = this.svgCanvas.getRotationAngle(elem); @@ -764,7 +764,7 @@ class Editor extends EditorStartup { } else { this.curContext = null; } - $id('cur_context_panel').style.display = (Boolean(context)) ? 'block' : 'none'; + $id('cur_context_panel').style.display = context ? 'block' : 'none'; // eslint-disable-next-line no-unsanitized/property $id('cur_context_panel').innerHTML = linkStr; @@ -801,9 +801,6 @@ class Editor extends EditorStartup { */ async extAdded(win, ext) { - const self = this; - // eslint-disable-next-line sonarjs/no-unused-collection - let btnSelects = []; if (!ext) { return undefined; } @@ -820,117 +817,6 @@ class Editor extends EditorStartup { } }; - if (ext.context_tools) { - ext.context_tools.forEach(function (tool, i) { - // Add select tool - const contId = tool.container_id ? (' id="' + tool.container_id + '"') : ''; - - let panel = $id(tool.panel); - // create the panel if it doesn't exist - if (!panel) { - panel = document.createElement("div"); - panel.id = tool.panel; - $id('tools_top').appendChild(panel); - } - - let html; - // TODO: Allow support for other types, or adding to existing tool - switch (tool.type) { - case 'tool_button': { - html = document.createElement("div"); - html.className = "tool_button"; - html.textContent = tool.id - panel.appendChild(html); - if (tool.events) { - tool.events.forEach((func, evt) => { - html.addEventListener(evt, func); - }); - } - break; - } case 'select': { - label = document.createElement("label"); - if (tool.container_id) { - label.id = tool.container_id; - } - html = ''; - // eslint-disable-next-line no-unsanitized/property - label.innerHTML = html; - // Creates the tool, hides & adds it, returns the select element - panel.appendChild(label); - - const sel = label.querySelector('select'); - - tool.events.forEach((func, evt) => { - sel.addEventListener(evt, func); - }); - break; - } case 'button-select': { - const div = document.createElement("div"); - div.id = tool.id; - div.className = "dropdown toolset"; - div.title = tool.title; - // eslint-disable-next-line no-unsanitized/property - div.innerHTML = '
'; - - const list = document.createElement("ul"); - list.id = tool.id; - - if ($id('option_lists')) $id('option_lists').appendChild(list); - - if (tool.colnum) { - list.className = ('optcols' + tool.colnum); - } - panel.appendChild(div); - // Creates the tool, hides & adds it, returns the select element - - btnSelects.push({ - elem: ('#' + tool.id), - list: ('#' + tool.id + '_opts'), - title: tool.title, - callback: tool.events.change, - cur: ('#cur_' + tool.id) - }); - - break; - } case 'input': { - const html = document.createElement("label"); - if (tool.container_id) { html.id = tool.container_id; } - html.innerHTML - - // eslint-disable-next-line no-unsanitized/property - html.innerHTML = '' + - tool.label + ':' + - ''; - - // Creates the tool, hides & adds it, returns the select element - - // Add to given tool.panel - panel.appendChild(html); - const inp = html.querySelector('input'); - - if (tool.spindata) { - inp.SpinButton(tool.spindata); - } - if (tool?.events !== undefined) { - Object.entries(tool.events).forEach((entry) => { - const [evt, func] = entry; - inp.addEventListener(evt, func); - }); - } - break; - } default: - break; - } - }); - } - if (ext.events) { this.leftPanel.add(ext.events.id, ext.events.click); } @@ -1177,7 +1063,7 @@ class Editor extends EditorStartup { const oldLayerName = ($id('#layerlist')) ? $id('#layerlist').querySelector('tr.layersel td.layername').textContent : ""; const renameLayer = (oldLayerName === this.uiStrings.common.layer + ' 1'); - this.svgCanvas.setUiStrings(allStrings); + // this.svgCanvas.setUiStrings(allStrings); this.setTitles(); if (renameLayer) { diff --git a/src/editor/EditorStartup.js b/src/editor/EditorStartup.js index c9eafaaa..49009cd0 100644 --- a/src/editor/EditorStartup.js +++ b/src/editor/EditorStartup.js @@ -62,7 +62,7 @@ class EditorStartup { */ async init () { const self = this; - const { i18next, langParam } = await putLocale(this.configObj.pref('lang'), this.goodLangs); + const { i18next } = await putLocale(this.configObj.pref('lang'), this.goodLangs); this.i18next = i18next; // allow to prepare the dom without display this.$svgEditor.style.visibility = 'hidden'; @@ -291,6 +291,7 @@ class EditorStartup { if (evt.type === 'mouseup') { panning = false; } return false; }); + // eslint-disable-next-line sonarjs/no-identical-functions $id('svgcanvas').addEventListener('mousemove', function(evt) { if (panning === false) { return true; } @@ -313,7 +314,7 @@ class EditorStartup { return true; }); - window.addEventListener('mouseup', function(evt) { + window.addEventListener('mouseup', function() { panning = false; }); @@ -362,7 +363,7 @@ class EditorStartup { }; const liElems = document.getElementById('svg_editor').querySelectorAll('button, select, input:not(#text)'); - Array.prototype.forEach.call(liElems, function(el, i){ + Array.prototype.forEach.call(liElems, function(el){ el.addEventListener("focus", (e) => { inp = e.currentTarget; this.uiContext = 'toolbars'; @@ -402,7 +403,7 @@ class EditorStartup { height: getHeight() }; - window.addEventListener('resize', (evt) => { + window.addEventListener('resize', () => { Object.entries(winWh).forEach(([type, val]) => { const curval = (type === 'width') ? window.innerWidth - 15 : window.innerHeight; this.workarea['scroll' + (type === 'width' ? 'Left' : 'Top')] -= (curval - val) / 2; @@ -531,7 +532,7 @@ class EditorStartup { $id('tool_wireframe').click(); } - $id('rulers').style.display = (Boolean(this.configObj.curConfig.showRulers)) ? 'block' : 'none'; + $id('rulers').style.display = (this.configObj.curConfig.showRulers) ? 'block' : 'none'; if (this.configObj.curConfig.showRulers) { $editDialog.setAttribute('showrulers', true); @@ -712,6 +713,7 @@ class EditorStartup { /** * @type {module:SVGthis.ExtensionObject} */ + // eslint-disable-next-line no-unsanitized/method const imported = await import(`./extensions/${encodeURIComponent(extname)}/${encodeURIComponent(extname)}.js`); const {name = extname, init: initfn} = imported.default; return this.addExtension(name, (initfn && initfn.bind(this)), {$, langParam: 'en'}); /** @todo change to current lng */ @@ -735,9 +737,10 @@ class EditorStartup { /** * @type {module:SVGthis.ExtensionObject} */ + // eslint-disable-next-line no-unsanitized/method const imported = await import(encodeURI(extPathName)); const {name, init: initfn} = imported.default; - return this.addExtension(name, (initfn && initfn.bind(this)), {$, langParam}); + return this.addExtension(name, (initfn && initfn.bind(this)), {$}); } catch (err) { // Todo: Add config to alert any errors console.error('Extension failed to load: ' + extPathName + '; ', err); @@ -748,12 +751,12 @@ class EditorStartup { this.svgCanvas.bind( 'extensions_added', /** - * @param {external:Window} win - * @param {module:svgcanvas.SvgCanvas#event:extensions_added} data + * @param {external:Window} _win + * @param {module:svgcanvas.SvgCanvas#event:extensions_added} _data * @listens module:SvgCanvas#event:extensions_added * @returns {void} */ - (win, data) => { + (_win, _data) => { this.extensionsAdded = true; this.setAll(); diff --git a/src/editor/MainMenu.js b/src/editor/MainMenu.js index 0692ada1..6234ff08 100644 --- a/src/editor/MainMenu.js +++ b/src/editor/MainMenu.js @@ -1,3 +1,4 @@ +/* globals seConfirm, seAlert */ import SvgCanvas from "../svgcanvas/svgcanvas.js"; import {convertUnit, isValidUnit} from '../common/units.js'; import {isChrome} from '../common/browser.js'; @@ -181,7 +182,7 @@ class MainMenu { const blob = new Blob([popHTML], { type: "text/html" }); popURL = URL.createObjectURL(blob); } else { - popURL = "data:text/html;base64;charset=utf-8," + encode64(popHTML); + popURL = "data:text/html;base64;charset=utf-8," + popHTML; } this.editor.loadingURL = popURL; } @@ -334,13 +335,13 @@ class MainMenu { this.clickOpen(); window.dispatchEvent(new CustomEvent("openImage")); }); - $id("tool_import").addEventListener("click", e => { + $id("tool_import").addEventListener("click", () => { this.clickImport(); window.dispatchEvent(new CustomEvent("importImages")); }); $id("tool_save").addEventListener( "click", - function(e) { + function() { const $editorDialog = document.getElementById("se-svg-editor-dialog"); const editingsource = $editorDialog.getAttribute("dialog") === "open"; if (editingsource) { @@ -351,7 +352,7 @@ class MainMenu { }.bind(this) ); // this.clickExport.bind(this) - $id("tool_export").addEventListener("click", function(e) { + $id("tool_export").addEventListener("click", function() { document .getElementById("se-export-dialog") .setAttribute("dialog", "open"); diff --git a/src/editor/components/jgraduate/Util.js b/src/editor/components/jgraduate/Util.js index 47d80a72..05001789 100644 --- a/src/editor/components/jgraduate/Util.js +++ b/src/editor/components/jgraduate/Util.js @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/no-collapsible-if */ /** * @param {any} obj * @returns {any} @@ -9,7 +10,7 @@ export function findPos(obj) { do { curleft += obj.offsetLeft; curtop += obj.offsetTop; - } while (obj = obj.offsetParent); + } while (obj == obj.offsetParent); return { left: curleft, top: curtop }; } return { left: curleft, top: curtop }; @@ -93,7 +94,7 @@ export function getClosest(elem, selector) { } } return null; -}; +} /** * Get all DOM element up the tree that contain a class, ID, or data attribute @@ -142,7 +143,7 @@ export function getClosest(elem, selector) { } else { return parents; } -}; +} export function getParentsUntil(elem, parent, selector) { let parents = []; @@ -214,4 +215,4 @@ export function getParentsUntil(elem, parent, selector) { } else { return parents; } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/editor/components/jgraduate/jQuery.jGraduate.js b/src/editor/components/jgraduate/jQuery.jGraduate.js index 04cf06b4..bcc8340f 100644 --- a/src/editor/components/jgraduate/jQuery.jGraduate.js +++ b/src/editor/components/jgraduate/jQuery.jGraduate.js @@ -46,8 +46,8 @@ const ns = { if (!window.console) { window.console = { - log (str) { /* empty fn */ }, - dir (str) { /* empty fn */ } + log () { /* empty fn */ }, + dir () { /* empty fn */ } }; } @@ -156,34 +156,6 @@ function mkElem (name, attrs, newparent) { return elem; } -function deepExtend(out) { - out = out || {}; - - for (let i = 1, len = arguments.length; i < len; ++i) { - let obj = arguments[i]; - - if (!obj) { - continue; - } - - for (const key in obj) { - if (!obj.hasOwnProperty(key)) { - continue; - } - - // based on https://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/ - if (Object.prototype.toString.call(obj[key]) === '[object Object]') { - out[key] = deepExtend(out[key], obj[key]); - continue; - } - - out[key] = obj[key]; - } - } - - return out; -} - /** * @typedef {PlainObject} module:jGraduate.ColorOpac Object may have one or both values * @property {string} [color] #Hex color @@ -221,8 +193,6 @@ export function jGraduateMethod (elem, options, okCallback, cancelCallback) { $settings = Object.assign({}, jGraduateDefaults, options || {}), id = $this.getAttribute('id'), idref = '#' + $this.getAttribute('id') + ' '; - // JFH !!!!! - const $shadowRoot = elem.parentNode; if (!idref) { // eslint-disable-next-line no-alert @@ -561,7 +531,7 @@ export function jGraduateMethod (elem, options, okCallback, cancelCallback) { $elem.style.top = e.target.value * MAX; } }; - for (const [i, attr] of ['x1', 'y1', 'x2', 'y2', 'cx', 'cy', 'fx', 'fy'].entries()) { + for (const [, attr] of ['x1', 'y1', 'x2', 'y2', 'cx', 'cy', 'fx', 'fy'].entries()) { const isRadial = isNaN(attr[1]); let attrval = curGradient.getAttribute(attr); @@ -653,7 +623,7 @@ export function jGraduateMethod (elem, options, okCallback, cancelCallback) { window: {title: 'Pick the start color and opacity for the gradient'}, images: {clientPath: $settings.images.clientPath}, color: {active: colr, alphaSupport: true} - }, function (clr, arg2) { + }, function (clr) { stopColor = clr.val('hex') ? ('#' + clr.val('hex')) : 'none'; stopOpacity = clr.val('a') !== null ? clr.val('a') / 256 : 1; colorhandle.setAttribute('fill', stopColor); @@ -1118,7 +1088,7 @@ export function jGraduateMethod (elem, options, okCallback, cancelCallback) { val: angleVal } }; - for (const [index, [type, data]] of Object.entries(Object.entries(sliders))) { + for (const [, [type, data]] of Object.entries(Object.entries(sliders))) { const handle = $this.querySelector(data.handle); const sInput = $this.querySelector(data.input); handle.addEventListener('mousedown', function (evt) { @@ -1190,7 +1160,7 @@ export function jGraduateMethod (elem, options, okCallback, cancelCallback) { evt.preventDefault(); }; - const stopSlider = function (evt) { + const stopSlider = function () { $win.removeEventListener('mousemove', dragSlider); $win.removeEventListener('mouseup', stopSlider); slider = null; diff --git a/src/editor/components/seListItem.js b/src/editor/components/seListItem.js index a13f8295..c238b203 100644 --- a/src/editor/components/seListItem.js +++ b/src/editor/components/seListItem.js @@ -48,6 +48,7 @@ export class SeListItem extends HTMLElement { */ attributeChangedCallback (name, oldValue, newValue) { if (oldValue === newValue) return; + // eslint-disable-next-line sonarjs/no-small-switch switch (name) { case 'option': this.$menuitem.setAttribute('option', newValue); diff --git a/src/editor/components/seSpinInput.js b/src/editor/components/seSpinInput.js index 9a588589..911601cc 100644 --- a/src/editor/components/seSpinInput.js +++ b/src/editor/components/seSpinInput.js @@ -178,6 +178,7 @@ export class SESpinInput extends HTMLElement { this.value = e.target.value; this.dispatchEvent(this.$event); }); + // eslint-disable-next-line sonarjs/no-identical-functions this.$input.addEventListener('click', (e) => { e.preventDefault(); this.value = e.target.value; diff --git a/src/editor/dialogs/cmenuLayersDialog.js b/src/editor/dialogs/cmenuLayersDialog.js index 0f0a494b..9e2ab506 100644 --- a/src/editor/dialogs/cmenuLayersDialog.js +++ b/src/editor/dialogs/cmenuLayersDialog.js @@ -107,6 +107,7 @@ export class SeCMenuLayerDialog extends HTMLElement { */ attributeChangedCallback (name, oldValue, newValue) { if (oldValue === newValue) return; + // eslint-disable-next-line sonarjs/no-small-switch switch (name) { case 'value': this.source = newValue; diff --git a/src/editor/dialogs/editorPreferencesDialog.js b/src/editor/dialogs/editorPreferencesDialog.js index 28947366..45a67dc4 100644 --- a/src/editor/dialogs/editorPreferencesDialog.js +++ b/src/editor/dialogs/editorPreferencesDialog.js @@ -483,13 +483,13 @@ export class SeEditPrefsDialog extends HTMLElement { * @returns {void} */ connectedCallback () { - const onCancelHandler = (ev) => { + const onCancelHandler = () => { const closeEvent = new CustomEvent('change', {detail: { dialog: 'closed' }}); this.dispatchEvent(closeEvent); }; - const onSaveHandler = (ev) => { + const onSaveHandler = () => { const color = this.$bgBlocks.querySelector('.cur_background').dataset.bgColor || '#FFF'; const closeEvent = new CustomEvent('change', {detail: { lang: this.$langSelect.value, @@ -506,7 +506,7 @@ export class SeEditPrefsDialog extends HTMLElement { }; // Set up editor background functionality const currentObj = this; - this.colorBlocks.forEach(function (e, i) { + this.colorBlocks.forEach(function (e) { const newdiv = document.createElement('div'); if (e === 'chessboard') { newdiv.dataset.bgColor = e; diff --git a/src/editor/dialogs/exportDialog.js b/src/editor/dialogs/exportDialog.js index 49bb5cae..05ab0b1f 100644 --- a/src/editor/dialogs/exportDialog.js +++ b/src/editor/dialogs/exportDialog.js @@ -119,6 +119,7 @@ export class SeExportDialog extends HTMLElement { * @returns {void} */ attributeChangedCallback (name, oldValue, newValue) { + // eslint-disable-next-line sonarjs/no-small-switch switch (name) { case 'dialog': if (newValue === 'open') { diff --git a/src/editor/dialogs/imagePropertiesDialog.js b/src/editor/dialogs/imagePropertiesDialog.js index d1f78677..9238a0b9 100644 --- a/src/editor/dialogs/imagePropertiesDialog.js +++ b/src/editor/dialogs/imagePropertiesDialog.js @@ -323,7 +323,7 @@ export class SeImgPropDialog extends HTMLElement { this.$canvasHeight.removeAttribute('disabled'); } }; - const onSaveHandler = (ev) => { + const onSaveHandler = () => { let saveOpt = ''; const w = this.$canvasWidth.value; const h = this.$canvasHeight.value; @@ -355,7 +355,7 @@ export class SeImgPropDialog extends HTMLElement { this.$resolution.selectedIndex = 0; this.dispatchEvent(closeEvent); }; - const onCancelHandler = (ev) => { + const onCancelHandler = () => { const closeEvent = new CustomEvent('change', {detail: { dialog: 'closed' }}); diff --git a/src/editor/dialogs/svgSourceDialog.js b/src/editor/dialogs/svgSourceDialog.js index 706ae7d2..1be00077 100644 --- a/src/editor/dialogs/svgSourceDialog.js +++ b/src/editor/dialogs/svgSourceDialog.js @@ -204,13 +204,13 @@ export class SeSvgSourceEditorDialog extends HTMLElement { * @returns {void} */ connectedCallback () { - const onCancelHandler = (ev) => { + const onCancelHandler = () => { const closeEvent = new CustomEvent('change', {detail: { dialog: 'closed' }}); this.dispatchEvent(closeEvent); }; - const onCopyHandler = (ev) => { + const onCopyHandler = () => { const closeEvent = new CustomEvent('change', { detail: { copy: 'click', @@ -219,7 +219,7 @@ export class SeSvgSourceEditorDialog extends HTMLElement { }); this.dispatchEvent(closeEvent); }; - const onSaveHandler = (ev) => { + const onSaveHandler = () => { const closeEvent = new CustomEvent('change', {detail: { value: this.$sourceTxt.value, dialog: 'close' diff --git a/src/editor/dragmove/dragmove.js b/src/editor/dragmove/dragmove.js index 24713bb0..64d69da8 100644 --- a/src/editor/dragmove/dragmove.js +++ b/src/editor/dragmove/dragmove.js @@ -47,7 +47,7 @@ export const dragmove = function(target, handler, parent, onStart, onEnd, onDrag }); // On leaving click, stop moving. - document.addEventListener(_isTouch ? "touchend" : "mouseup", function(e) { + document.addEventListener(_isTouch ? "touchend" : "mouseup", function() { if (onEnd && hasStarted) { onEnd(target, parent, parseInt(target.style.left), parseInt(target.style.top)); } @@ -57,7 +57,7 @@ export const dragmove = function(target, handler, parent, onStart, onEnd, onDrag }); // On leaving click, stop moving. - document.addEventListener(_isTouch ? "touchmove" : "mousemove", function(e) { + document.addEventListener(_isTouch ? "touchmove" : "mousemove", function() { if (onDrag && hasStarted) { onDrag(target, parseInt(target.style.left), parseInt(target.style.top)); } diff --git a/src/editor/embedapi-dom.js b/src/editor/embedapi-dom.js index c37ad994..a7954a0c 100644 --- a/src/editor/embedapi-dom.js +++ b/src/editor/embedapi-dom.js @@ -1,4 +1,3 @@ -/* globals jQuery */ /** * Attaches items to DOM for Embedded SVG support. * @module EmbeddedSVGEditDOM @@ -6,8 +5,6 @@ import EmbeddedSVGEdit from './embedapi.js'; import {isChrome} from '../common/browser.js'; -const $ = jQuery; - let svgCanvas = null; /** @@ -110,6 +107,7 @@ iframe.src = frameBase + framePath + iframe.addEventListener('load', function () { svgCanvas = new EmbeddedSVGEdit(frame, [new URL(frameBase).origin]); + const {$id} = svgCanvas; // Hide main button, as we will be controlling new, load, save, etc. from the host document let doc; try { diff --git a/src/editor/extensions/ext-arrows/ext-arrows.js b/src/editor/extensions/ext-arrows/ext-arrows.js index d43f7a66..2fa2e451 100644 --- a/src/editor/extensions/ext-arrows/ext-arrows.js +++ b/src/editor/extensions/ext-arrows/ext-arrows.js @@ -11,6 +11,7 @@ const loadExtensionTranslation = async function (svgEditor) { let translationModule; const lang = svgEditor.configObj.pref('lang') try { + // eslint-disable-next-line no-unsanitized/method translationModule = await import(`./locale/${encodeURIComponent(lang)}.js`); } catch (_error) { // eslint-disable-next-line no-console @@ -29,7 +30,7 @@ export default { const {$id} = svgCanvas; const addElem = svgCanvas.addSVGElementFromJson, - {nonce, $} = S, + {nonce} = S, prefix = 'se_arrow_'; let selElems, arrowprefix, randomizeIds = S.randomize_ids; @@ -50,7 +51,7 @@ export default { * @param {Window} win * @returns {void} */ - function unsetArrowNonce (win) { + function unsetArrowNonce (_win) { randomizeIds = false; arrowprefix = prefix; pathdata.fw.id = arrowprefix + 'fw'; @@ -216,7 +217,7 @@ export default { const mtypes = ['start', 'mid', 'end']; const defs = svgCanvas.findDefs(); - mtypes.forEach(function(type, i){ + mtypes.forEach(function(type){ const marker = getLinked(elem, 'marker-' + type); if (!marker) { return; } @@ -251,8 +252,8 @@ export default { // Check if last marker can be removed let remove = true; const sElements = S.svgcontent.querySelectorAll('line, polyline, path, polygon'); - Array.prototype.forEach.call(sElements, function(element, i){ - mtypes.forEach(function(mtype, j){ + Array.prototype.forEach.call(sElements, function(element){ + mtypes.forEach(function(mtype){ if (element.getAttribute('marker-' + mtype) === 'url(#' + marker.id + ')') { remove = false; return remove; @@ -293,7 +294,7 @@ export default { // Set ID so it can be translated in locale file $id('arrow_list option').setAttribute('id', 'connector_no_arrow'); }, - async addLangData ({lang, importLocale}) { + async addLangData ({_lang, importLocale}) { const {langList} = await importLocale(); return { data: langList diff --git a/src/editor/extensions/ext-closepath/ext-closepath.js b/src/editor/extensions/ext-closepath/ext-closepath.js index f18bfa44..0e057555 100644 --- a/src/editor/extensions/ext-closepath/ext-closepath.js +++ b/src/editor/extensions/ext-closepath/ext-closepath.js @@ -10,6 +10,7 @@ const loadExtensionTranslation = async function (lang) { let translationModule; try { + // eslint-disable-next-line no-unsanitized/method translationModule = await import(`./locale/${encodeURIComponent(lang)}.js`); } catch (_error) { // eslint-disable-next-line no-console @@ -23,7 +24,7 @@ const loadExtensionTranslation = async function (lang) { // The button toggles whether the path is open or closed export default { name: 'closepath', - async init ({importLocale, $}) { + async init ({_importLocale}) { const svgEditor = this; const {svgCanvas} = svgEditor; const {$id} = svgCanvas; @@ -34,8 +35,8 @@ export default { closed = seglist.getItem(seglist.numberOfItems - 1).pathSegType === 1, showbutton = closed ? 'tool_openpath' : 'tool_closepath', hidebutton = closed ? 'tool_closepath' : 'tool_openpath'; - $id("hidebutton").style.display = 'none'; - $id("showbutton").style.display = 'block'; + $id(hidebutton).style.display = 'none'; + $id(showbutton).style.display = 'block'; }; const showPanel = function (on) { $id('closepath_panel').style.display = (on) ? 'block' : 'none'; diff --git a/src/editor/extensions/ext-connector/ext-connector.js b/src/editor/extensions/ext-connector/ext-connector.js index 7638a7f6..00c4b1b0 100644 --- a/src/editor/extensions/ext-connector/ext-connector.js +++ b/src/editor/extensions/ext-connector/ext-connector.js @@ -10,6 +10,7 @@ const loadExtensionTranslation = async function (lang) { let translationModule; try { + // eslint-disable-next-line no-unsanitized/method translationModule = await import(`./locale/${encodeURIComponent(lang)}.js`); } catch (_error) { // eslint-disable-next-line no-console @@ -197,7 +198,7 @@ export default { connections = []; // Loop through connectors to see if one is connected to the element - Array.prototype.forEach.call(connectors, function (ethis, i) { + Array.prototype.forEach.call(connectors, function (ethis) { let addThis; // Grab the ends const parts = []; @@ -220,7 +221,7 @@ export default { addThis = false; // The connected element might be part of a selected group const parents = svgCanvas.getParents(cElem.parentNode); - Array.prototype.forEach.call(parents, function (el, i) { + Array.prototype.forEach.call(parents, function (el) { if (elems.includes(el)) { // Pretend this element is selected addThis = true; @@ -364,7 +365,7 @@ export default { svgCanvas.setMode('connector'); }); }, - /* async */ addLangData({ lang }) { // , importLocale: importLoc + /* async */ addLangData({ _lang }) { // , importLocale: importLoc return { data: strings.langList }; @@ -505,7 +506,7 @@ export default { const connStr = startId + ' ' + endId; const altStr = endId + ' ' + startId; // Don't create connector if one already exists - const dupe = Array.prototype.filter.call(svgcontent.querySelectorAll('.se_connector'), function (aThis, i) { + const dupe = Array.prototype.filter.call(svgcontent.querySelectorAll('.se_connector'), function (aThis) { const conn = aThis.getAttributeNS(seNs, 'connector'); if (conn === connStr || conn === altStr) { return true; } return false; diff --git a/src/editor/extensions/ext-eyedropper/ext-eyedropper.js b/src/editor/extensions/ext-eyedropper/ext-eyedropper.js index db992a1d..b2fb1526 100644 --- a/src/editor/extensions/ext-eyedropper/ext-eyedropper.js +++ b/src/editor/extensions/ext-eyedropper/ext-eyedropper.js @@ -10,6 +10,7 @@ const loadExtensionTranslation = async function (lang) { let translationModule; try { + // eslint-disable-next-line no-unsanitized/method translationModule = await import(`./locale/${encodeURIComponent(lang)}.js`); } catch (_error) { // eslint-disable-next-line no-console @@ -24,7 +25,7 @@ export default { async init(S) { const svgEditor = this; const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang')); - const { $, ChangeElementCommand } = S, // , svgcontent, + const { ChangeElementCommand } = S, // , svgcontent, // svgdoc = S.svgroot.parentNode.ownerDocument, { svgCanvas } = svgEditor, addToHistory = function (cmd) { svgCanvas.undoMgr.addCommandToHistory(cmd); }, diff --git a/src/editor/extensions/ext-foreignobject/ext-foreignobject.js b/src/editor/extensions/ext-foreignobject/ext-foreignobject.js index 498f50ad..c0089e4f 100644 --- a/src/editor/extensions/ext-foreignobject/ext-foreignobject.js +++ b/src/editor/extensions/ext-foreignobject/ext-foreignobject.js @@ -10,6 +10,7 @@ const loadExtensionTranslation = async function (lang) { let translationModule; try { + // eslint-disable-next-line no-unsanitized/method translationModule = await import(`./locale/${encodeURIComponent(lang)}.js`); } catch (_error) { // eslint-disable-next-line no-console @@ -23,7 +24,7 @@ export default { name: 'foreignobject', async init (S) { const svgEditor = this; - const {$, text2xml, NS} = S; + const {text2xml, NS} = S; const {svgCanvas} = svgEditor; const {$id} = svgCanvas; const @@ -35,7 +36,7 @@ export default { const properlySourceSizeTextArea = function () { // TODO: remove magic numbers here and get values from CSS - const height = parseFloat(getComputedStyle($id(svg_source_container), null).height.replace("px", "")) - 80; + const height = parseFloat(getComputedStyle($id('svg_source_container'), null).height.replace("px", "")) - 80; $id('svg_source_textarea').style.height = height + "px"; }; @@ -207,7 +208,7 @@ export default { // const oldElement = $id('tool_source_save'); // oldElement.parentNode.replaceChild(toolSourceSave, oldElement); $id('tool_source_back').append(toolSourceSave); - toolSourceSave.addEventListener('click', (e) => function () { + toolSourceSave.addEventListener('click', () => function () { if (!editingforeign) { return; } if (!setForeignString($id('svg_source_textarea').value)) { @@ -225,7 +226,7 @@ export default { toolSourceCancel.style.display = 'none'; toolSourceCancel.id = 'foreign_cancel'; $id('tool_source_back').append(toolSourceCancel); - toolSourceCancel.addEventListener('click', (e) => function () { + toolSourceCancel.addEventListener('click', () => function () { endChanges(); }); // unbind() @@ -268,7 +269,7 @@ export default { started: true }; }, - mouseUp (opts) { + mouseUp (_opts) { // const e = opts.event; if (svgCanvas.getMode() !== 'foreign' || !started) { return undefined; @@ -306,7 +307,7 @@ export default { } } }, - elementChanged (opts) { + elementChanged (_opts) { // const elem = opts.elems[0]; } }; diff --git a/src/editor/extensions/ext-grid/ext-grid.js b/src/editor/extensions/ext-grid/ext-grid.js index 3d927cfe..800f32de 100644 --- a/src/editor/extensions/ext-grid/ext-grid.js +++ b/src/editor/extensions/ext-grid/ext-grid.js @@ -10,6 +10,7 @@ const loadExtensionTranslation = async function (lang) { let translationModule; try { + // eslint-disable-next-line no-unsanitized/method translationModule = await import(`./locale/${encodeURIComponent(lang)}.js`); } catch (_error) { // eslint-disable-next-line no-console @@ -21,7 +22,7 @@ const loadExtensionTranslation = async function (lang) { export default { name: 'grid', - async init ({$, NS, getTypeMap}) { + async init ({NS, getTypeMap}) { const svgEditor = this; const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang')); const {svgCanvas} = svgEditor; diff --git a/src/editor/extensions/ext-helloworld/ext-helloworld.js b/src/editor/extensions/ext-helloworld/ext-helloworld.js index 2f47f965..dff5a96c 100644 --- a/src/editor/extensions/ext-helloworld/ext-helloworld.js +++ b/src/editor/extensions/ext-helloworld/ext-helloworld.js @@ -16,6 +16,7 @@ const loadExtensionTranslation = async function (lang) { let translationModule; try { + // eslint-disable-next-line no-unsanitized/method translationModule = await import(`./locale/${encodeURIComponent(lang)}.js`); } catch (_error) { // eslint-disable-next-line no-console @@ -27,7 +28,7 @@ const loadExtensionTranslation = async function (lang) { export default { name: 'helloworld', - async init ({$, importLocale}) { + async init ({_importLocale}) { const svgEditor = this; const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang')); const {svgCanvas} = svgEditor; diff --git a/src/editor/extensions/ext-imagelib/ext-imagelib.js b/src/editor/extensions/ext-imagelib/ext-imagelib.js index 20b78301..e094d8a1 100644 --- a/src/editor/extensions/ext-imagelib/ext-imagelib.js +++ b/src/editor/extensions/ext-imagelib/ext-imagelib.js @@ -12,6 +12,7 @@ const loadExtensionTranslation = async function (lang) { let translationModule; try { + // eslint-disable-next-line no-unsanitized/method translationModule = await import(`./locale/${encodeURIComponent(lang)}.js`); } catch (_error) { // eslint-disable-next-line no-console @@ -23,7 +24,7 @@ const loadExtensionTranslation = async function (lang) { export default { name: 'imagelib', - async init({ $, decode64, dropXMLInternalSubset }) { + async init({ decode64, dropXMLInternalSubset }) { const svgEditor = this; const { $id } = svgEditor.svgCanvas; const imagelibStrings = await loadExtensionTranslation(svgEditor.configObj.pref('lang')); @@ -436,6 +437,7 @@ export default { header.textContent = allLibs; back.style.display = 'none'; }); + // eslint-disable-next-line sonarjs/no-identical-functions back.addEventListener('touchend', function () { frame.setAttribute('src', 'about:blank'); frame.style.display = 'none'; @@ -479,6 +481,7 @@ export default { libOpts.style.display = 'none'; back.style.display = 'block'; }); + // eslint-disable-next-line sonarjs/no-identical-functions li.addEventListener('touchend', function () { frame.setAttribute('src', url); frame.style.display = 'block'; diff --git a/src/editor/extensions/ext-imagelib/index.js b/src/editor/extensions/ext-imagelib/index.js index c1a3cff5..289ff64e 100644 --- a/src/editor/extensions/ext-imagelib/index.js +++ b/src/editor/extensions/ext-imagelib/index.js @@ -1,7 +1,7 @@ /* globals jQuery */ const $ = jQuery; const atags = document.querySelectorAll('a'); -Array.prototype.forEach.call(atags, function (aEle, i) { +Array.prototype.forEach.call(atags, function (aEle) { aEle.addEventListener('click', function (event) { const { href } = event.currentTarget; const target = window.parent; diff --git a/src/editor/extensions/ext-markers/ext-markers.js b/src/editor/extensions/ext-markers/ext-markers.js index 19f945f7..b3888525 100644 --- a/src/editor/extensions/ext-markers/ext-markers.js +++ b/src/editor/extensions/ext-markers/ext-markers.js @@ -32,6 +32,7 @@ const loadExtensionTranslation = async function (lang) { let translationModule; try { + // eslint-disable-next-line no-unsanitized/method translationModule = await import(`./locale/${encodeURIComponent(lang)}.js`); } catch (_error) { // eslint-disable-next-line no-console @@ -452,7 +453,7 @@ export default { * @param {Event} ev * @returns {Promise