identation requirement to eslint

This commit is contained in:
JFH
2021-05-28 10:35:46 +02:00
parent 1e73db7f5c
commit 01b022b1e7
39 changed files with 1832 additions and 1846 deletions

View File

@@ -23,6 +23,8 @@ module.exports = {
rules: { rules: {
/** @todo len should probably more 120-150 */ /** @todo len should probably more 120-150 */
"max-len": [ "warn", { "code": 250 } ], "max-len": [ "warn", { "code": 250 } ],
"indent": [ "error", 2 ],
"no-var": "error",
/** @todo jsdoc should be made warn or error */ /** @todo jsdoc should be made warn or error */
"valid-jsdoc": "off", "valid-jsdoc": "off",
/** @todo cognitive complexity should be much lower (25-50?) */ /** @todo cognitive complexity should be much lower (25-50?) */

View File

@@ -33,7 +33,7 @@ describe('recalculate', function () {
return this._storage.has(element) && this._storage.get(element).has(key); return this._storage.has(element) && this._storage.get(element).has(key);
}, },
remove: function (element, key) { remove: function (element, key) {
var ret = this._storage.get(element).delete(key); let ret = this._storage.get(element).delete(key);
if (!this._storage.get(element).size === 0) { if (!this._storage.get(element).size === 0) {
this._storage.delete(element); this._storage.delete(element);
} }

View File

@@ -27,7 +27,7 @@ describe('select', function () {
return this._storage.has(element) && this._storage.get(element).has(key); return this._storage.has(element) && this._storage.get(element).has(key);
}, },
remove: function (element, key) { remove: function (element, key) {
var ret = this._storage.get(element).delete(key); let ret = this._storage.get(element).delete(key);
if (!this._storage.get(element).size === 0) { if (!this._storage.get(element).size === 0) {
this._storage.delete(element); this._storage.delete(element);
} }

View File

@@ -145,13 +145,13 @@ import { importSetGlobalDefault } from '../external/dynamic-import-polyfill/impo
(async () => { (async () => {
const url = `${svgEditor.curConfig.extPath}ext-locale/<extNameWithoutExtPrefix>/<lang>.js`; const url = `${svgEditor.curConfig.extPath}ext-locale/<extNameWithoutExtPrefix>/<lang>.js`;
const localeStrings = await importSetGlobalDefault(url, { const localeStrings = await importSetGlobalDefault(url, {
global: 'svgEditorExtensionLocale_imagelib_' + lang global: 'svgEditorExtensionLocale_imagelib_' + lang
}); });
// Use `localeStrings` // Use `localeStrings`
console.info(localeStrings); console.info(localeStrings);
})(); })();
``` ```

View File

@@ -11,7 +11,7 @@ import 'pathseg';
import { NS } from './namespaces.js'; import { NS } from './namespaces.js';
const supportsSVG_ = (function () { const supportsSVG_ = (function () {
return Boolean(document.createElementNS && document.createElementNS(NS.SVG, 'svg').createSVGRect); return Boolean(document.createElementNS && document.createElementNS(NS.SVG, 'svg').createSVGRect);
}()); }());
/** /**
@@ -33,108 +33,108 @@ const isMac_ = userAgent.includes('Macintosh');
const isTouch_ = 'ontouchstart' in window; const isTouch_ = 'ontouchstart' in window;
const supportsSelectors_ = (function () { const supportsSelectors_ = (function () {
return Boolean(svg.querySelector); return Boolean(svg.querySelector);
}()); }());
const supportsXpath_ = (function () { const supportsXpath_ = (function () {
return Boolean(document.evaluate); return Boolean(document.evaluate);
}()); }());
// segList functions (for FF1.5 and 2.0) // segList functions (for FF1.5 and 2.0)
const supportsPathReplaceItem_ = (function () { const supportsPathReplaceItem_ = (function () {
const path = document.createElementNS(NS.SVG, 'path'); const path = document.createElementNS(NS.SVG, 'path');
path.setAttribute('d', 'M0,0 10,10'); path.setAttribute('d', 'M0,0 10,10');
const seglist = path.pathSegList; const seglist = path.pathSegList;
const seg = path.createSVGPathSegLinetoAbs(5, 5); const seg = path.createSVGPathSegLinetoAbs(5, 5);
try { try {
seglist.replaceItem(seg, 1); seglist.replaceItem(seg, 1);
return true; return true;
}catch (err) {/* empty */} }catch (err) {/* empty */}
return false; return false;
}()); }());
const supportsPathInsertItemBefore_ = (function () { const supportsPathInsertItemBefore_ = (function () {
const path = document.createElementNS(NS.SVG, 'path'); const path = document.createElementNS(NS.SVG, 'path');
path.setAttribute('d', 'M0,0 10,10'); path.setAttribute('d', 'M0,0 10,10');
const seglist = path.pathSegList; const seglist = path.pathSegList;
const seg = path.createSVGPathSegLinetoAbs(5, 5); const seg = path.createSVGPathSegLinetoAbs(5, 5);
try { try {
seglist.insertItemBefore(seg, 1); seglist.insertItemBefore(seg, 1);
return true; return true;
}catch (err) {/* empty */} }catch (err) {/* empty */}
return false; return false;
}()); }());
// text character positioning (for IE9 and now Chrome) // text character positioning (for IE9 and now Chrome)
const supportsGoodTextCharPos_ = (function () { const supportsGoodTextCharPos_ = (function () {
const svgroot = document.createElementNS(NS.SVG, 'svg'); const svgroot = document.createElementNS(NS.SVG, 'svg');
const svgcontent = document.createElementNS(NS.SVG, 'svg'); const svgcontent = document.createElementNS(NS.SVG, 'svg');
document.documentElement.append(svgroot); document.documentElement.append(svgroot);
svgcontent.setAttribute('x', 5); svgcontent.setAttribute('x', 5);
svgroot.append(svgcontent); svgroot.append(svgcontent);
const text = document.createElementNS(NS.SVG, 'text'); const text = document.createElementNS(NS.SVG, 'text');
text.textContent = 'a'; text.textContent = 'a';
svgcontent.append(text); svgcontent.append(text);
try { // Chrome now fails here try { // Chrome now fails here
const pos = text.getStartPositionOfChar(0).x; const pos = text.getStartPositionOfChar(0).x;
return (pos === 0); return (pos === 0);
} catch (err) { } catch (err) {
return false; return false;
} finally { } finally {
svgroot.remove(); svgroot.remove();
} }
}()); }());
const supportsPathBBox_ = (function () { const supportsPathBBox_ = (function () {
const svgcontent = document.createElementNS(NS.SVG, 'svg'); const svgcontent = document.createElementNS(NS.SVG, 'svg');
document.documentElement.append(svgcontent); document.documentElement.append(svgcontent);
const path = document.createElementNS(NS.SVG, 'path'); const path = document.createElementNS(NS.SVG, 'path');
path.setAttribute('d', 'M0,0 C0,0 10,10 10,0'); path.setAttribute('d', 'M0,0 C0,0 10,10 10,0');
svgcontent.append(path); svgcontent.append(path);
const bbox = path.getBBox(); const bbox = path.getBBox();
svgcontent.remove(); svgcontent.remove();
return (bbox.height > 4 && bbox.height < 5); return (bbox.height > 4 && bbox.height < 5);
}()); }());
// Support for correct bbox sizing on groups with horizontal/vertical lines // Support for correct bbox sizing on groups with horizontal/vertical lines
const supportsHVLineContainerBBox_ = (function () { const supportsHVLineContainerBBox_ = (function () {
const svgcontent = document.createElementNS(NS.SVG, 'svg'); const svgcontent = document.createElementNS(NS.SVG, 'svg');
document.documentElement.append(svgcontent); document.documentElement.append(svgcontent);
const path = document.createElementNS(NS.SVG, 'path'); const path = document.createElementNS(NS.SVG, 'path');
path.setAttribute('d', 'M0,0 10,0'); path.setAttribute('d', 'M0,0 10,0');
const path2 = document.createElementNS(NS.SVG, 'path'); const path2 = document.createElementNS(NS.SVG, 'path');
path2.setAttribute('d', 'M5,0 15,0'); path2.setAttribute('d', 'M5,0 15,0');
const g = document.createElementNS(NS.SVG, 'g'); const g = document.createElementNS(NS.SVG, 'g');
g.append(path, path2); g.append(path, path2);
svgcontent.append(g); svgcontent.append(g);
const bbox = g.getBBox(); const bbox = g.getBBox();
svgcontent.remove(); svgcontent.remove();
// Webkit gives 0, FF gives 10, Opera (correctly) gives 15 // Webkit gives 0, FF gives 10, Opera (correctly) gives 15
return (bbox.width === 15); return (bbox.width === 15);
}()); }());
const supportsEditableText_ = (function () { const supportsEditableText_ = (function () {
// TODO: Find better way to check support for this // TODO: Find better way to check support for this
return isOpera_; return isOpera_;
}()); }());
const supportsNonScalingStroke_ = (function () { const supportsNonScalingStroke_ = (function () {
const rect = document.createElementNS(NS.SVG, 'rect'); const rect = document.createElementNS(NS.SVG, 'rect');
rect.setAttribute('style', 'vector-effect:non-scaling-stroke'); rect.setAttribute('style', 'vector-effect:non-scaling-stroke');
return rect.style.vectorEffect === 'non-scaling-stroke'; return rect.style.vectorEffect === 'non-scaling-stroke';
}()); }());
let supportsNativeSVGTransformLists_ = (function () { let supportsNativeSVGTransformLists_ = (function () {
const rect = document.createElementNS(NS.SVG, 'rect'); const rect = document.createElementNS(NS.SVG, 'rect');
const rxform = rect.transform.baseVal; const rxform = rect.transform.baseVal;
const t1 = svg.createSVGTransform(); const t1 = svg.createSVGTransform();
rxform.appendItem(t1); rxform.appendItem(t1);
const r1 = rxform.getItem(0); const r1 = rxform.getItem(0);
const isSVGTransform = (o) => { const isSVGTransform = (o) => {
// https://developer.mozilla.org/en-US/docs/Web/API/SVGTransform // https://developer.mozilla.org/en-US/docs/Web/API/SVGTransform
return o && typeof o === 'object' && typeof o.setMatrix === 'function' && 'angle' in o; return o && typeof o === 'object' && typeof o.setMatrix === 'function' && 'angle' in o;
}; };
return isSVGTransform(r1) && isSVGTransform(t1) && return isSVGTransform(r1) && isSVGTransform(t1) &&
r1.type === t1.type && r1.angle === t1.angle && r1.type === t1.type && r1.angle === t1.angle &&
r1.matrix.a === t1.matrix.a && r1.matrix.a === t1.matrix.a &&
r1.matrix.b === t1.matrix.b && r1.matrix.b === t1.matrix.b &&

View File

@@ -281,11 +281,11 @@ class Editor extends EditorStartup {
parentSelector = document; parentSelector = document;
} }
var parents = []; let parents = [];
var p = el.parentNode; let p = el.parentNode;
while (p !== parentSelector) { while (p !== parentSelector) {
var o = p; let o = p;
parents.push(o); parents.push(o);
p = o.parentNode; p = o.parentNode;
} }

View File

@@ -255,8 +255,8 @@ class EditorStartup {
}); });
function addListenerMulti(element, eventNames, listener) { function addListenerMulti(element, eventNames, listener) {
var events = eventNames.split(' '); let events = eventNames.split(' ');
for (var i=0, iLen=events.length; i<iLen; i++) { for (let i=0, iLen=events.length; i<iLen; i++) {
element.addEventListener(events[i], listener, false); element.addEventListener(events[i], listener, false);
} }
} }

View File

@@ -102,7 +102,7 @@ export function getClosest(elem, selector) {
* @param {String} selector The class, id, data attribute, or tag to look for * @param {String} selector The class, id, data attribute, or tag to look for
* @return {Array} Null if no match * @return {Array} Null if no match
*/ */
export function getParents(elem, selector) { export function getParents(elem, selector) {
const parents = []; const parents = [];
let firstChar; let firstChar;
if ( selector ) { if ( selector ) {

View File

@@ -221,7 +221,7 @@ export default {
// setSelectMode(); // setSelectMode();
}); });
var oldToolSourceCancel = $id('tool_source_cancel'); let oldToolSourceCancel = $id('tool_source_cancel');
const toolSourceCancel = oldToolSourceCancel.cloneNode(true); const toolSourceCancel = oldToolSourceCancel.cloneNode(true);
toolSourceCancel.style.display = 'none'; toolSourceCancel.style.display = 'none';
toolSourceCancel.id = 'foreign_cancel'; toolSourceCancel.id = 'foreign_cancel';

View File

@@ -7,9 +7,9 @@
* *
*/ */
const name = "grid"; const name = "grid";
const loadExtensionTranslation = async function (svgEditor) { const loadExtensionTranslation = async function (svgEditor) {
let translationModule; let translationModule;
const lang = svgEditor.configObj.pref('lang'); const lang = svgEditor.configObj.pref('lang');
try { try {

View File

@@ -9,9 +9,9 @@
* *
*/ */
const name = "imagelib"; const name = "imagelib";
const loadExtensionTranslation = async function (svgEditor) { const loadExtensionTranslation = async function (svgEditor) {
let translationModule; let translationModule;
const lang = svgEditor.configObj.pref('lang'); const lang = svgEditor.configObj.pref('lang');
try { try {
@@ -24,7 +24,7 @@
translationModule = await import(`./locale/en.js`); translationModule = await import(`./locale/en.js`);
} }
svgEditor.i18next.addResourceBundle(lang, name, translationModule.default); svgEditor.i18next.addResourceBundle(lang, name, translationModule.default);
}; };
export default { export default {
name, name,
@@ -507,7 +507,7 @@ export default {
libOpts.style.display = 'none'; libOpts.style.display = 'none';
back.style.display = 'block'; back.style.display = 'block';
}); });
var span = document.createElement("span"); let span = document.createElement("span");
span.textContent = description; span.textContent = description;
li.appendChild(span); li.appendChild(span);
}); });

View File

@@ -104,7 +104,7 @@ export default {
const items = txt.split(';'); const items = txt.split(';');
selElems.forEach((elem) => { selElems.forEach((elem) => {
if (elem && elem.getAttribute('class').includes('placemark')) { if (elem && elem.getAttribute('class').includes('placemark')) {
var elements = elem.children; let elements = elem.children;
Array.prototype.forEach.call(elements, function(i, _){ Array.prototype.forEach.call(elements, function(i, _){
const [ , , type, n ] = i.id.split('_'); const [ , , type, n ] = i.id.split('_');
if (type === 'txt') { if (type === 'txt') {
@@ -125,7 +125,7 @@ export default {
font = font.join(' '); font = font.join(' ');
selElems.forEach((elem) => { selElems.forEach((elem) => {
if (elem && elem.getAttribute('class').includes('placemark')) { if (elem && elem.getAttribute('class').includes('placemark')) {
var elements = elem.children; let elements = elem.children;
Array.prototype.forEach.call(elements, function(i, _){ Array.prototype.forEach.call(elements, function(i, _){
const [ , , type ] = i.id.split('_'); const [ , , type ] = i.id.split('_');
if (type === 'txt') { if (type === 'txt') {

View File

@@ -8,7 +8,7 @@
* *
*/ */
import i18next from 'i18next'; import i18next from 'i18next';
/** /**
* Used, for example, in the ImageLibs extension, to present libraries * Used, for example, in the ImageLibs extension, to present libraries

View File

@@ -283,7 +283,7 @@ class LayersPanel {
index(el) { index(el) {
if (!el) return -1; if (!el) return -1;
var i = 0; let i = 0;
do { do {
i++; i++;
} while (el == el.previousElementSibling); } while (el == el.previousElementSibling);

View File

@@ -237,7 +237,7 @@ export const cloneSelectedElements = function (x, y) {
function index(el) { function index(el) {
if (!el) return -1; if (!el) return -1;
var i = 0; let i = 0;
do { do {
i++; i++;
} while (el == el.previousElementSibling); } while (el == el.previousElementSibling);

View File

@@ -209,7 +209,7 @@ class SvgCanvas {
return this._storage.has(element) && this._storage.get(element).has(key); return this._storage.has(element) && this._storage.get(element).has(key);
}, },
remove: function (element, key) { remove: function (element, key) {
var ret = this._storage.get(element).delete(key); let ret = this._storage.get(element).delete(key);
if (!this._storage.get(element).size === 0) { if (!this._storage.get(element).size === 0) {
this._storage.delete(element); this._storage.delete(element);
} }
@@ -787,65 +787,49 @@ class SvgCanvas {
*/ */
// Object to contain image data for raster images that were found encodable // Object to contain image data for raster images that were found encodable
const encodableImages = {}, const encodableImages = {};
// Object with save options // Object with save options
/** /**
* @type {module:svgcanvas.SaveOptions} * @type {module:svgcanvas.SaveOptions}
*/ */
saveOptions = { round_digits: 5 }, const saveOptions = { round_digits: 5 };
// Object with IDs for imported files, to see if one was already added // Object with IDs for imported files, to see if one was already added
importIds = {}, const importIds = {};
// Current text style properties // Current text style properties
curText = allProperties.text, const curText = allProperties.text;
// Object to contain all included extensions // Object to contain all included extensions
extensions = {}, const extensions = {};
// Map of deleted reference elements // Map of deleted reference elements
removedElements = {}; const removedElements = {};
let
// String with image URL of last loadable image // String with image URL of last loadable image
lastGoodImgUrl = curConfig.imgPath + 'logo.svg', let lastGoodImgUrl = curConfig.imgPath + 'logo.svg';
// Boolean indicating whether or not a draw action has been started // Boolean indicating whether or not a draw action has been started
started = false, let started = false;
// String with an element's initial transform attribute value // String with an element's initial transform attribute value
startTransform = null, let startTransform = null;
// String indicating the current editor mode // String indicating the current editor mode
currentMode = 'select', let currentMode = 'select';
// String with the current direction in which an element is being resized // String with the current direction in which an element is being resized
currentResizeMode = 'none', let currentResizeMode = 'none';
// Current general properties // Current general properties
curProperties = curShape, let curProperties = curShape;
// Array with selected elements' Bounding box object // Array with selected elements' Bounding box object
// selectedBBoxes = new Array(1), // selectedBBoxes = new Array(1),
// The DOM element that was just selected // The DOM element that was just selected
justSelected = null, let justSelected = null;
// DOM element for selection rectangle drawn by the user // DOM element for selection rectangle drawn by the user
rubberBox = null, let rubberBox = null;
// Array of current BBoxes, used in getIntersectionList(). // Array of current BBoxes, used in getIntersectionList().
curBBoxes = [], let curBBoxes = [];
// Canvas point for the most recent right click // Canvas point for the most recent right click
lastClickPoint = null; let lastClickPoint = null;
this.runExtension = function (name, action, vars) { this.runExtension = function (name, action, vars) {
return this.runExtensions(action, vars, false, (n) => n === name); return this.runExtensions(action, vars, false, (n) => n === name);
}; };
/* eslint-disable max-len */ /* eslint-disable max-len */
/** /**
* @todo Consider: Should this return an array by default, so extension results aren't overwritten? * @todo Consider: Should this return an array by default, so extension results aren't overwritten?
* @todo Would be easier to document if passing in object with key of action and vars as value; could then define an interface which tied both together * @todo Would be easier to document if passing in object with key of action and vars as value; could then define an interface which tied both together
* @function module:svgcanvas.SvgCanvas#runExtensions * @function module:svgcanvas.SvgCanvas#runExtensions
@@ -855,7 +839,7 @@ class SvgCanvas {
* @param {module:svgcanvas.ExtensionNameFilter} nameFilter * @param {module:svgcanvas.ExtensionNameFilter} nameFilter
* @returns {GenericArray<module:svgcanvas.ExtensionStatus>|module:svgcanvas.ExtensionStatus|false} See {@tutorial ExtensionDocs} on the ExtensionStatus. * @returns {GenericArray<module:svgcanvas.ExtensionStatus>|module:svgcanvas.ExtensionStatus|false} See {@tutorial ExtensionDocs} on the ExtensionStatus.
*/ */
/* eslint-enable max-len */ /* eslint-enable max-len */
this.runExtensions = runExtensionsMethod; this.runExtensions = runExtensionsMethod;
@@ -1037,14 +1021,14 @@ class SvgCanvas {
* @event module:svgcanvas.SvgCanvas#event:exportedPDF * @event module:svgcanvas.SvgCanvas#event:exportedPDF
* @type {module:svgcanvas.PDFExportedResults} * @type {module:svgcanvas.PDFExportedResults}
*/ */
/* eslint-disable max-len */ /* eslint-disable max-len */
/** /**
* Creating a cover-all class until {@link https://github.com/jsdoc3/jsdoc/issues/1545} may be supported. * Creating a cover-all class until {@link https://github.com/jsdoc3/jsdoc/issues/1545} may be supported.
* `undefined` may be returned by {@link module:svgcanvas.SvgCanvas#event:extension_added} if the extension's `init` returns `undefined` It is also the type for the following events "zoomDone", "unsetnonce", "cleared", and "extensions_added". * `undefined` may be returned by {@link module:svgcanvas.SvgCanvas#event:extension_added} if the extension's `init` returns `undefined` It is also the type for the following events "zoomDone", "unsetnonce", "cleared", and "extensions_added".
* @event module:svgcanvas.SvgCanvas#event:GenericCanvasEvent * @event module:svgcanvas.SvgCanvas#event:GenericCanvasEvent
* @type {module:svgcanvas.SvgCanvas#event:selected|module:svgcanvas.SvgCanvas#event:changed|module:svgcanvas.SvgCanvas#event:contextset|module:svgcanvas.SvgCanvas#event:pointsAdded|module:svgcanvas.SvgCanvas#event:extension_added|module:svgcanvas.SvgCanvas#event:extensions_added|module:svgcanvas.SvgCanvas#event:message|module:svgcanvas.SvgCanvas#event:transition|module:svgcanvas.SvgCanvas#event:zoomed|module:svgcanvas.SvgCanvas#event:updateCanvas|module:svgcanvas.SvgCanvas#event:saved|module:svgcanvas.SvgCanvas#event:exported|module:svgcanvas.SvgCanvas#event:exportedPDF|module:svgcanvas.SvgCanvas#event:setnonce|module:svgcanvas.SvgCanvas#event:unsetnonce|void} * @type {module:svgcanvas.SvgCanvas#event:selected|module:svgcanvas.SvgCanvas#event:changed|module:svgcanvas.SvgCanvas#event:contextset|module:svgcanvas.SvgCanvas#event:pointsAdded|module:svgcanvas.SvgCanvas#event:extension_added|module:svgcanvas.SvgCanvas#event:extensions_added|module:svgcanvas.SvgCanvas#event:message|module:svgcanvas.SvgCanvas#event:transition|module:svgcanvas.SvgCanvas#event:zoomed|module:svgcanvas.SvgCanvas#event:updateCanvas|module:svgcanvas.SvgCanvas#event:saved|module:svgcanvas.SvgCanvas#event:exported|module:svgcanvas.SvgCanvas#event:exportedPDF|module:svgcanvas.SvgCanvas#event:setnonce|module:svgcanvas.SvgCanvas#event:unsetnonce|void}
*/ */
/* eslint-enable max-len */ /* eslint-enable max-len */
/** /**
* The promise return, if present, resolves to `undefined` * The promise return, if present, resolves to `undefined`
@@ -1059,7 +1043,7 @@ class SvgCanvas {
* @listens module:svgcanvas.SvgCanvas#event:GenericCanvasEvent * @listens module:svgcanvas.SvgCanvas#event:GenericCanvasEvent
* @returns {module:svgcanvas.EventHandlerReturn} * @returns {module:svgcanvas.EventHandlerReturn}
*/ */
/* eslint-disable max-len */ /* eslint-disable max-len */
/** /**
* Attaches a callback function to an event. * Attaches a callback function to an event.
* @function module:svgcanvas.SvgCanvas#bind * @function module:svgcanvas.SvgCanvas#bind
@@ -1067,7 +1051,7 @@ class SvgCanvas {
* @param {module:svgcanvas.EventHandler} f - The callback function to bind to the event * @param {module:svgcanvas.EventHandler} f - The callback function to bind to the event
* @returns {module:svgcanvas.EventHandler} The previous event * @returns {module:svgcanvas.EventHandler} The previous event
*/ */
/* eslint-enable max-len */ /* eslint-enable max-len */
canvas.bind = function (ev, f) { canvas.bind = function (ev, f) {
const old = events[ev]; const old = events[ev];
events[ev] = f; events[ev] = f;