From 074df9cdec8ad9baf89081c3004a85dc09fffdc1 Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Mon, 31 May 2021 00:09:51 +0200 Subject: [PATCH] eslint: enforce use of const when variable not modified --- .eslintrc.js | 10 ++++++++-- cypress/integration/unit/recalculate.js | 2 +- cypress/integration/unit/select.js | 2 +- src/editor/Editor.js | 4 ++-- src/editor/EditorStartup.js | 2 +- src/editor/components/jgraduate/Util.js | 4 ++-- src/editor/components/jgraduate/jQuery.jPicker.js | 2 +- .../extensions/ext-foreignobject/ext-foreignobject.js | 2 +- src/editor/extensions/ext-helloworld/ext-helloworld.js | 2 +- src/editor/extensions/ext-imagelib/ext-imagelib.js | 2 +- .../ext-overview_window/dragmove/dragmove.js | 2 +- src/editor/extensions/ext-placemark/ext-placemark.js | 4 ++-- .../extensions/ext-server_opensave/ext-php_savefile.js | 2 +- src/svgcanvas/draw.js | 2 +- src/svgcanvas/svgcanvas.js | 4 ++-- src/svgcanvas/utilities.js | 2 +- 16 files changed, 27 insertions(+), 21 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 1819e570..ae593bc2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -32,12 +32,17 @@ module.exports = { /** @todo cognitive complexity should be much lower (25-50?) */ "sonarjs/cognitive-complexity": [ "warn", 200 ], /** @todo no param reassign creates too many warnings but should be a warning */ - "comma-dangle": [ "error" ], "no-param-reassign": "off", + /** @todo no use before define creates too many warnings but should be a warning */ + "no-use-before-define": "off", + /** @todo camel case creates too many warnings but should be a warning */ + "camelcase": "off", + "comma-dangle": [ "error" ], "node/no-unsupported-features/es-syntax": 0, "no-unused-vars": [ "error", { "argsIgnorePattern": "^_" } ], "sonarjs/no-duplicate-string": 0, "semi" : "error", + "prefer-const": "error", "no-trailing-spaces": "error", "array-bracket-spacing": [ "error", "always" ], "comma-spacing": "error", @@ -85,7 +90,8 @@ module.exports = { { files: [ 'src/editor/locale/*.js' ], rules: { // lang files may have long length - "max-len": "off" + "max-len": "off", + "camelcase": "off" } } ] diff --git a/cypress/integration/unit/recalculate.js b/cypress/integration/unit/recalculate.js index e81610f0..cf6254a9 100644 --- a/cypress/integration/unit/recalculate.js +++ b/cypress/integration/unit/recalculate.js @@ -33,7 +33,7 @@ describe('recalculate', function () { return this._storage.has(element) && this._storage.get(element).has(key); }, remove: function (element, key) { - let ret = this._storage.get(element).delete(key); + const ret = this._storage.get(element).delete(key); if (!this._storage.get(element).size === 0) { this._storage.delete(element); } diff --git a/cypress/integration/unit/select.js b/cypress/integration/unit/select.js index 0dba2bb0..f4c83df2 100644 --- a/cypress/integration/unit/select.js +++ b/cypress/integration/unit/select.js @@ -27,7 +27,7 @@ describe('select', function () { return this._storage.has(element) && this._storage.get(element).has(key); }, remove: function (element, key) { - let ret = this._storage.get(element).delete(key); + const ret = this._storage.get(element).delete(key); if (!this._storage.get(element).size === 0) { this._storage.delete(element); } diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 99886243..b8a7420b 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -281,11 +281,11 @@ class Editor extends EditorStartup { parentSelector = document; } - let parents = []; + const parents = []; let p = el.parentNode; while (p !== parentSelector) { - let o = p; + const o = p; parents.push(o); p = o.parentNode; } diff --git a/src/editor/EditorStartup.js b/src/editor/EditorStartup.js index 3ca32dd8..50b1a7f6 100644 --- a/src/editor/EditorStartup.js +++ b/src/editor/EditorStartup.js @@ -255,7 +255,7 @@ class EditorStartup { }); function addListenerMulti(element, eventNames, listener) { - let events = eventNames.split(' '); + const events = eventNames.split(' '); for (let i=0, iLen=events.length; i { if (isObject(source[key])) { @@ -146,7 +146,7 @@ export function getParents(elem, selector) { } export function getParentsUntil(elem, parent, selector) { - let parents = []; + const parents = []; let parentType; let selectorType; if ( parent ) { diff --git a/src/editor/components/jgraduate/jQuery.jPicker.js b/src/editor/components/jgraduate/jQuery.jPicker.js index 2cd62d1d..58bf20a9 100755 --- a/src/editor/components/jgraduate/jQuery.jPicker.js +++ b/src/editor/components/jgraduate/jQuery.jPicker.js @@ -1652,7 +1652,7 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc let iconColor = null; // iconColor for popup icon let iconAlpha = null; // iconAlpha for popup icon let iconImage = null; // iconImage popup icon - let moveBar = null; // drag bar + const moveBar = null; // drag bar Object.assign(that, { // public properties, methods, and callbacks commitCallback, // commitCallback function can be overridden to return the selected color to a method you specify when the user clicks "OK" diff --git a/src/editor/extensions/ext-foreignobject/ext-foreignobject.js b/src/editor/extensions/ext-foreignobject/ext-foreignobject.js index 9dd7a5b8..24e0797c 100644 --- a/src/editor/extensions/ext-foreignobject/ext-foreignobject.js +++ b/src/editor/extensions/ext-foreignobject/ext-foreignobject.js @@ -221,7 +221,7 @@ export default { // setSelectMode(); }); - let oldToolSourceCancel = $id('tool_source_cancel'); + const oldToolSourceCancel = $id('tool_source_cancel'); const toolSourceCancel = oldToolSourceCancel.cloneNode(true); toolSourceCancel.style.display = 'none'; toolSourceCancel.id = 'foreign_cancel'; diff --git a/src/editor/extensions/ext-helloworld/ext-helloworld.js b/src/editor/extensions/ext-helloworld/ext-helloworld.js index b6c46cba..43bc7598 100644 --- a/src/editor/extensions/ext-helloworld/ext-helloworld.js +++ b/src/editor/extensions/ext-helloworld/ext-helloworld.js @@ -76,7 +76,7 @@ export default { const y = opts.mouse_y / zoom; // We do our own formatting - let text = svgEditor.i18next.t(`${name}:text`, { x, y }); + const text = svgEditor.i18next.t(`${name}:text`, { x, y }); // Show the text using the custom alert function alert(text); } diff --git a/src/editor/extensions/ext-imagelib/ext-imagelib.js b/src/editor/extensions/ext-imagelib/ext-imagelib.js index e4dcfcc9..07e6ce2d 100644 --- a/src/editor/extensions/ext-imagelib/ext-imagelib.js +++ b/src/editor/extensions/ext-imagelib/ext-imagelib.js @@ -507,7 +507,7 @@ export default { libOpts.style.display = 'none'; back.style.display = 'block'; }); - let span = document.createElement("span"); + const span = document.createElement("span"); span.textContent = description; li.appendChild(span); }); diff --git a/src/editor/extensions/ext-overview_window/dragmove/dragmove.js b/src/editor/extensions/ext-overview_window/dragmove/dragmove.js index 2b5d876f..04348e31 100644 --- a/src/editor/extensions/ext-overview_window/dragmove/dragmove.js +++ b/src/editor/extensions/ext-overview_window/dragmove/dragmove.js @@ -4,7 +4,7 @@ // can't use npm version as the dragmove is different. let _loaded = false; -let _callbacks = []; +const _callbacks = []; const _isTouch = window.ontouchstart !== undefined; export const dragmove = function(target, handler, parent, onStart, onEnd, onDrag) { diff --git a/src/editor/extensions/ext-placemark/ext-placemark.js b/src/editor/extensions/ext-placemark/ext-placemark.js index cd34abf2..27f0452c 100644 --- a/src/editor/extensions/ext-placemark/ext-placemark.js +++ b/src/editor/extensions/ext-placemark/ext-placemark.js @@ -104,7 +104,7 @@ export default { const items = txt.split(';'); selElems.forEach((elem) => { if (elem && elem.getAttribute('class').includes('placemark')) { - let elements = elem.children; + const elements = elem.children; Array.prototype.forEach.call(elements, function(i, _){ const [ , , type, n ] = i.id.split('_'); if (type === 'txt') { @@ -125,7 +125,7 @@ export default { font = font.join(' '); selElems.forEach((elem) => { if (elem && elem.getAttribute('class').includes('placemark')) { - let elements = elem.children; + const elements = elem.children; Array.prototype.forEach.call(elements, function(i, _){ const [ , , type ] = i.id.split('_'); if (type === 'txt') { diff --git a/src/editor/extensions/ext-server_opensave/ext-php_savefile.js b/src/editor/extensions/ext-server_opensave/ext-php_savefile.js index dfa9e452..c256f87e 100644 --- a/src/editor/extensions/ext-server_opensave/ext-php_savefile.js +++ b/src/editor/extensions/ext-server_opensave/ext-php_savefile.js @@ -23,7 +23,7 @@ export default { const filename = getFileNameFromTitle(); // $.post(saveSvgAction, { output_svg: svg, filename }); - let postData = { output_svg: svg, filename }; + const postData = { output_svg: svg, filename }; fetch(saveSvgAction, { method: "POST", body: JSON.stringify(postData) diff --git a/src/svgcanvas/draw.js b/src/svgcanvas/draw.js index 6e7ef811..01806af2 100644 --- a/src/svgcanvas/draw.js +++ b/src/svgcanvas/draw.js @@ -1020,7 +1020,7 @@ export const setContext = function (elem) { // Disable other elements const parentsUntil = getParentsUntil(elem, '#svgcontent'); - let siblings = []; + const siblings = []; parentsUntil.forEach(function (parent) { const elements = Array.prototype.filter.call(parent.parentNode.children, function(child){ return child !== parent; diff --git a/src/svgcanvas/svgcanvas.js b/src/svgcanvas/svgcanvas.js index 752dcadf..42e8bcc8 100644 --- a/src/svgcanvas/svgcanvas.js +++ b/src/svgcanvas/svgcanvas.js @@ -209,7 +209,7 @@ class SvgCanvas { return this._storage.has(element) && this._storage.get(element).has(key); }, remove: function (element, key) { - let ret = this._storage.get(element).delete(key); + const ret = this._storage.get(element).delete(key); if (!this._storage.get(element).size === 0) { this._storage.delete(element); } @@ -555,7 +555,7 @@ class SvgCanvas { const restoreRefElems = function (elem) { // Look for missing reference elements, restore any found - let attrs = {}; + const attrs = {}; refAttrs.forEach(function (item, _) { attrs[item] = elem.getAttribute(item); }); diff --git a/src/svgcanvas/utilities.js b/src/svgcanvas/utilities.js index 372e9e84..6b356fcd 100644 --- a/src/svgcanvas/utilities.js +++ b/src/svgcanvas/utilities.js @@ -576,7 +576,7 @@ function groupBBFix(selected) { let ret; let copy; if (ref) { - let elements = []; + const elements = []; Array.prototype.forEach.call(ref.children, function (el) { const elem = el.cloneNode(true); elem.setAttribute('visibility', 'hidden');