From 7bf4ebd3df91600a9feeb9a0493c8a502dd1e3c9 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 27 Sep 2022 16:46:37 +0200 Subject: [PATCH] fix eslint errors --- Message/Request/Request.js | 2 +- Message/Response/ResponseManager.js | 2 +- Model/Action/Dom/FormSubmit.js | 8 ++++- System/SystemUtils.js | 8 ++--- UI/Component/Form.js | 56 +++++++++++++++++------------ UI/Component/Input.js | 1 - UI/GeneralUI.js | 2 +- UI/UIStateManager.js | 2 +- Uri/HttpUri.js | 4 ++- Utils/Debug.js | 2 ++ Utils/GeneralUtils.js | 2 +- Views/FormView.js | 2 +- 12 files changed, 56 insertions(+), 35 deletions(-) diff --git a/Message/Request/Request.js b/Message/Request/Request.js index 3631c9c..7282bef 100755 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -324,7 +324,7 @@ export class Request // GET request doesn't allow body/payload. Therefor we have to put the data into the uri if (this.method === RequestMethod.GET) { let url = this.uri; - for (let pair of this.data.entries()) { + for (const pair of this.data.entries()) { url += '&' + pair[0] + '=' + pair[1]; } diff --git a/Message/Response/ResponseManager.js b/Message/Response/ResponseManager.js index 3d214c1..a4389a1 100755 --- a/Message/Response/ResponseManager.js +++ b/Message/Response/ResponseManager.js @@ -67,7 +67,7 @@ export class ResponseManager ) { this.messages[key][request](data); } else if (typeof this.messages[key] !== 'undefined') { - this.messages[key][null](data); + this.messages[key].null(data); } else { jsOMS.Log.Logger.instance.warning('Undefined type: ' + key); } diff --git a/Model/Action/Dom/FormSubmit.js b/Model/Action/Dom/FormSubmit.js index dea2401..020d36a 100755 --- a/Model/Action/Dom/FormSubmit.js +++ b/Model/Action/Dom/FormSubmit.js @@ -11,7 +11,13 @@ export function formSubmitAction (action, callback, id) { 'use strict'; - const submit = action.base === 'self' ? (action.selector === '' ? [document.getElementById(id)] : document.getElementById(id).querySelectorAll(action.selector)) : document.querySelectorAll(action.selector); + const submit = action.base === 'self' + ? ( + action.selector === '' + ? [document.getElementById(id)] + : document.getElementById(id).querySelectorAll(action.selector) + ) + : document.querySelectorAll(action.selector); if (!submit) { return; diff --git a/System/SystemUtils.js b/System/SystemUtils.js index 8da571b..09304e9 100644 --- a/System/SystemUtils.js +++ b/System/SystemUtils.js @@ -29,15 +29,15 @@ export class SystemUtils return BrowserType.FIREFOX; } else if (Object.toString.call(window.HTMLElement).indexOf('Constructor') > 0) { return BrowserType.SAFARI; - } else if (/* @cc_on!@ */false || !!document.documentMode) { + } else if (/* @cc_on!@ */false || !!document.documentMode) { // eslint-disable-line no-extra-boolean-cast return BrowserType.IE; - } else if (!!window.StyleMedia) { + } else if (!!window.StyleMedia) { // eslint-disable-line no-extra-boolean-cast return BrowserType.EDGE; - } else if (!!window.chrome && !!window.chrome.webstore) { + } else if (!!window.chrome && !!window.chrome.webstore) { // eslint-disable-line no-extra-boolean-cast return BrowserType.CHROME; } else if (((typeof isChrome !== 'undefined' && isChrome) || (typeof isOpera !== 'undefined' && isOpera)) - && !!window.CSS + && !!window.CSS // eslint-disable-line no-extra-boolean-cast ) { return BrowserType.BLINK; } diff --git a/UI/Component/Form.js b/UI/Component/Form.js index 4032541..1d5c796 100755 --- a/UI/Component/Form.js +++ b/UI/Component/Form.js @@ -122,7 +122,7 @@ export class Form @todo: removed because sometimes it is already bound but bound in a wrong way (e.g. no success is defined) if (Object.prototype.hasOwnProperty.call(this.forms, id)) { return; - }*/ + } */ this.forms[id] = new FormView(id); const self = this; @@ -277,7 +277,10 @@ export class Form /** @var {Element} dataOriginElement Element where the value data comes from */ const dataOriginElement = tplValue.startsWith('http') || tplValue.startsWith('{') ? newElements[i].firstElementChild // data comes from remote source - : formElement; // data comes from the form (even if the api returns something after adding). What if remote returns a DB id? how do we add it? is this a @todo ? probably yes, maybe first use local data and then if remote data available replace local data? + : formElement; // data comes from the form (even if the api returns something after adding). + // What if remote returns a DB id? how do we add it? + // is this a @todo ? probably yes. + // maybe first use local data and then if remote data available replace local data? values = values.concat( dataOriginElement.hasAttribute('data-tpl-value') @@ -400,7 +403,10 @@ export class Form /** @var {Element} dataOriginElement Element where the value data comes from */ const dataOriginElement = tplValue.startsWith('http') || tplValue.startsWith('{') ? newElements[i].firstElementChild // data comes from remote source - : elementContainer; // data comes from the form (even if the api returns something after adding). What if remote returns a DB id? how do we add it? is this a @todo ? probably yes, maybe first use local data and then if remote data available replace local data? + : elementContainer; // data comes from the form (even if the api returns something after adding). + // What if remote returns a DB id? how do we add it? + // is this a @todo ? probably yes. + // maybe first use local data and then if remote data available replace local data? values = values.concat( dataOriginElement.hasAttribute('data-tpl-value') @@ -468,7 +474,10 @@ export class Form /** @var {Element} dataOriginElement Element where the value data comes from */ const dataOriginElement = updateValue.startsWith('http') || updateValue.startsWith('{') ? updateElements[i].firstElementChild // data comes from remote source - : elementContainer; // data comes from the form (even if the api returns something after adding). What if remote returns a DB id? how do we add it? is this a @todo ? probably yes, maybe first use local data and then if remote data available replace local data? + : elementContainer; // data comes from the form (even if the api returns something after adding). + // What if remote returns a DB id? how do we add it? + // is this a @todo ? probably yes. + // maybe first use local data and then if remote data available replace local data? values = values.concat( dataOriginElement.hasAttribute('data-tpl-value') @@ -554,7 +563,10 @@ export class Form /** @var {Element} dataOriginElement Element where the value data comes from */ const dataOriginElement = updateValue.startsWith('http') || updateValue.startsWith('{') ? updateElements[i].firstElementChild // data comes from remote source - : externalFormElement; // data comes from the form (even if the api returns something after adding). What if remote returns a DB id? how do we add it? is this a @todo ? probably yes, maybe first use local data and then if remote data available replace local data? + : externalFormElement; // data comes from the form (even if the api returns something after adding). + // What if remote returns a DB id? how do we add it? + // is this a @todo ? probably yes. + // maybe first use local data and then if remote data available replace local data? values = values.concat( dataOriginElement.hasAttribute('data-tpl-value') @@ -591,21 +603,21 @@ export class Form // show add button + hide update button + hide cancel button const addButtons = self.forms[externalFormId].getAdd(); - length = addButtons.length; + let buttonLength = addButtons.length; - for (let i = 0; i < length; ++i) { + for (let i = 0; i < buttonLength; ++i) { jsOMS.removeClass(addButtons[i], 'hidden'); } const saveButtons = self.forms[externalFormId].getSave(); - length = saveButtons.length; - for (let i = 0; i < length; ++i) { + buttonLength = saveButtons.length; + for (let i = 0; i < buttonLength; ++i) { jsOMS.addClass(saveButtons[i], 'hidden'); } const cancelButtons = self.forms[externalFormId].getCancel(); - length = cancelButtons.length; - for (let i = 0; i < length; ++i) { + buttonLength = cancelButtons.length; + for (let i = 0; i < buttonLength; ++i) { jsOMS.addClass(cancelButtons[i], 'hidden'); } } @@ -636,7 +648,7 @@ export class Form jsOMS.removeClass(element, 'hidden'); - elementContainer.parentNode.removeChild(elementContainer) + elementContainer.parentNode.removeChild(elementContainer); } else { // handle external cancel @@ -732,14 +744,14 @@ export class Form } const saveButtons = self.forms[id].getSave(); - length = saveButtons.length; - for (let i = 0; i < length; ++i) { + let buttonLength = saveButtons.length; + for (let i = 0; i < buttonLength; ++i) { jsOMS.removeClass(saveButtons[i], 'hidden'); } const cancelButtons = self.forms[id].getCancel(); - length = cancelButtons.length; - for (let i = 0; i < length; ++i) { + buttonLength = cancelButtons.length; + for (let i = 0; i < buttonLength; ++i) { jsOMS.removeClass(cancelButtons[i], 'hidden'); } } else { @@ -819,7 +831,7 @@ export class Form ) { jsOMS.preventAll(event); self.submit(self.forms[id], self.forms[id].getSubmit()[elementIndex]); - } else if ((elementIndex = '')) { + } else if (false) { // eslint-disable-line no-constant-condition // @todo: if table head input field in popups changes -> check if input empty -> deactivate -> checkbox : else activate checkbox // careful: the same checkbox is used for showing the filter popup. maybe create a separate checkbox, which only handles the highlighting if filter is defined. // this means popup active highlights filter icon AND different content checkbox also highlights filter @@ -962,7 +974,7 @@ export class Form request.setData(data); request.setType(RequestType.FORM_DATA); // @todo: consider to allow different request type - request.setUri(action ? action : form.getAction()); + request.setUri(action !== null ? action : form.getAction()); request.setMethod(form.getMethod()); request.setSuccess(function (xhr) { @@ -1157,7 +1169,7 @@ export class Form if (data[i].getAttribute('data-tpl-' + type).startsWith('http') || data[i].getAttribute('data-tpl-' + type).startsWith('{') ) { - Form.populateRemoteUrls(type, data[i], path, remoteUrls); + Form.populateRemoteUrls(matches[c], type, data[i], path, remoteUrls); } else { if (type === 'value') { GeneralUI.setValueOfElement(matches[c], GeneralUI.getValueFromDataSource(data[i])); @@ -1184,7 +1196,7 @@ export class Form if (data[i].getAttribute('data-tpl-' + type).startsWith('http') || data[i].getAttribute('data-tpl-' + type).startsWith('{') ) { - Form.populateRemoteUrls(type, data[i], path, remoteUrls); + Form.populateRemoteUrls(matches[c], type, data[i], path, remoteUrls); } else { if (type === 'value') { GeneralUI.setValueOfElement(matches[c], GeneralUI.getValueFromDataSource(data[i])); @@ -1196,7 +1208,7 @@ export class Form } }; - static populateRemoteUrls (type, data, path, remoteUrls) + static populateRemoteUrls (ele, type, data, path, remoteUrls) { const uri = data.getAttribute('data-tpl-' + type).startsWith('/') ? document.getElementsByTagName('base')[0].href @@ -1208,7 +1220,7 @@ export class Form remoteUrls[uri + data.getAttribute('data-tpl-' + type)].push({ path: path, - element: matches[c], + element: ele, type: type }); }; diff --git a/UI/Component/Input.js b/UI/Component/Input.js index 5965327..8135efb 100755 --- a/UI/Component/Input.js +++ b/UI/Component/Input.js @@ -95,7 +95,6 @@ export class Input const response = new Response(o); const responseLength = response.count(); let tempResponse = null; - let success = null; for (let k = 0; k < responseLength; ++k) { tempResponse = response.getByIndex(k); diff --git a/UI/GeneralUI.js b/UI/GeneralUI.js index 3e392ab..feee69a 100755 --- a/UI/GeneralUI.js +++ b/UI/GeneralUI.js @@ -216,7 +216,7 @@ export class GeneralUI const length = e.length; for (let i = 0; i < length; ++i) { - new AdvancedInput(e[i], this.app.eventManager, this.app.uiManager.getDOMObserver()); + new AdvancedInput(e[i], this.app.eventManager, this.app.uiManager.getDOMObserver()); // eslint-disable-line no-new } }; diff --git a/UI/UIStateManager.js b/UI/UIStateManager.js index b5ff244..433ec16 100644 --- a/UI/UIStateManager.js +++ b/UI/UIStateManager.js @@ -87,7 +87,7 @@ export class UIStateManager element.scrollLeft = state.x; element.scrollTop = state.y; - element.scrollTo({ top: state.y, left: state.x }) + element.scrollTo({ top: state.y, left: state.x }); element.addEventListener('scroll', function () { window.localStorage.setItem('ui-state-' + this.id, JSON.stringify({ x: this.scrollLeft, y: this.scrollTop })); diff --git a/Uri/HttpUri.js b/Uri/HttpUri.js index 7f80774..34460ec 100755 --- a/Uri/HttpUri.js +++ b/Uri/HttpUri.js @@ -77,11 +77,13 @@ export class HttpUri 'relative', 'path', 'directory', 'file', 'query', 'fragment' ]; + /* eslint-disable max-len */ const parser = { php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, - loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this) + loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ }; + /* eslint-enable max-len */ if (!Object.prototype.hasOwnProperty.call(parser, mode)) { throw new Error('Unexpected parsing mode.', 'UriFactory', 52); diff --git a/Utils/Debug.js b/Utils/Debug.js index 020b931..7692c0d 100755 --- a/Utils/Debug.js +++ b/Utils/Debug.js @@ -60,6 +60,7 @@ const validatePage = function (url) const aHref = document.querySelectorAll('a:not([alt]), a[href=""], a[href=" "], a[href="#"]'); findings[url].href_empty = aHref.length; + /* eslint-disable max-len */ // analyze inline on* function const onFunction = document.querySelectorAll('[onafterprint], [onbeforeprint], [onbeforeunload], [onerror], [onhaschange], [onload], [onmessage], [onoffline], [ononline], [onpagehide], [onpageshow], [onpopstate], [onredo], [onresize], [onstorage], [onundo], [onunload], [onblur], [onchage], [oncontextmenu], [onfocus], [onformchange], [onforminput], [oninput], [oninvalid], [onreset], [onselect], [onsubmit], [onkeydown], [onkeypress], [onkeyup], [onclick], [ondblclick], [ondrag], [ondragend], [ondragenter], [ondragleave], [ondragover], [ondragstart], [ondrop], [onmousedown], [onmousemove], [onmouseout], [onmouseover], [onmouseup], [onmousewheel], [onscroll], [onabort], [oncanplay], [oncanplaythrough], [ondurationchange], [onemptied], [onended], [onerror], [onloadeddata], [onloadedmetadata], [onloadstart], [onpause], [onplay], [onplaying], [onprogress], [onratechange], [onreadystatechange], [onseeked], [onseeking], [onstalled], [onsuspend], [ontimeupdate], [onvolumechange], [onwaiting]'); findings[url].js_on = onFunction.length; @@ -71,6 +72,7 @@ const validatePage = function (url) // analyze invalid container-children relationship (e.g. empty containers, invalid children) const invalidContainerChildren = document.querySelectorAll(':not(tr) > td, :not(tr) > th, colgroup *:not(col), :not(colgroup) > col, tr > :not(td):not(th), optgroup > :not(option), :not(select) > option, :not(fieldset) > legend, select > :not(option):not(optgroup), :not(select):not(optgroup) > option, table > *:not(thead):not(tfoot):not(tbody):not(tr):not(colgroup):not(caption)'); findings[url].invalid_container_children = invalidContainerChildren.length; + /* eslint-enable max-len */ // has inline styles const hasInlineStyles = document.querySelectorAll('*[style]'); diff --git a/Utils/GeneralUtils.js b/Utils/GeneralUtils.js index 048cd03..885f045 100755 --- a/Utils/GeneralUtils.js +++ b/Utils/GeneralUtils.js @@ -23,7 +23,7 @@ */ jsOMS.watcher = (function () { - var timer = 0; + var timer = 0; // eslint-disable-line no-var return function (callback, ms) { clearTimeout(timer); diff --git a/Views/FormView.js b/Views/FormView.js index fc53ce3..e9111d5 100755 --- a/Views/FormView.js +++ b/Views/FormView.js @@ -775,7 +775,7 @@ export class FormView } }; - getElementsToBind(e = null) + getElementsToBind (e = null) { const parent = e === null ? document : e;