From c629a4fdf1b52dca5f696dd3d40f61ab61019d00 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Tue, 22 Oct 2024 14:38:27 +0200 Subject: [PATCH] eslint: autofix all stylistic issues --- eslint.config.js | 23 --- .../CollapsingSectionNote/script.js | 168 +++++++++--------- 2 files changed, 82 insertions(+), 109 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index b6576a2..7effaa9 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -22,27 +22,4 @@ export default [ semi: true, braceStyle: "1tbs", }), - { - rules: { - "@stylistic/arrow-parens": "off", - "@stylistic/brace-style": "off", - "@stylistic/comma-dangle": "off", - "@stylistic/indent": "off", - "@stylistic/key-spacing": "off", - "@stylistic/keyword-spacing": "off", - "@stylistic/no-mixed-spaces-and-tabs": "off", - "@stylistic/no-multiple-empty-lines": "off", - "@stylistic/no-multi-spaces": "off", - "@stylistic/no-tabs": "off", - "@stylistic/no-trailing-spaces": "off", - "@stylistic/padded-blocks": "off", - "@stylistic/semi": "off", - "@stylistic/space-before-blocks": "off", - "@stylistic/space-before-function-paren": "off", - "@stylistic/spaced-comment": "off", - "@stylistic/space-infix-ops": "off", - "@stylistic/space-in-parens": "off", - "@stylistic/space-unary-ops": "off", - }, - }, ]; diff --git a/src/main/resources/org/jvnet/hudson/plugins/collapsingconsolesections/CollapsingSectionNote/script.js b/src/main/resources/org/jvnet/hudson/plugins/collapsingconsolesections/CollapsingSectionNote/script.js index cd80b16..ce755d9 100644 --- a/src/main/resources/org/jvnet/hudson/plugins/collapsingconsolesections/CollapsingSectionNote/script.js +++ b/src/main/resources/org/jvnet/hudson/plugins/collapsingconsolesections/CollapsingSectionNote/script.js @@ -1,7 +1,6 @@ // The doToggle method is used by CollapsingSectionAnnotator.java // eslint-disable-next-line no-unused-vars -function doToggle(o) -{ +function doToggle(o) { var section = o.parentNode.parentNode; if (section.nextElementSibling) { if (section.nextElementSibling.className === "collapsed") { @@ -12,13 +11,13 @@ function doToggle(o) o.innerHTML = "Show Details"; } } else { - if (section.nextSibling.className === "collapsed") { + if (section.nextSibling.className === "collapsed") { section.nextSibling.className = "expanded"; o.innerHTML = "Hide Details"; } else { section.nextSibling.className = "collapsed"; o.innerHTML = "Show Details"; - } + } } } @@ -30,29 +29,29 @@ document.addEventListener("DOMContentLoaded", function () { var queue = []; // console sections are queued up until we load outline. function getoffsets(object, offsets) { - if (! offsets) { - offsets = new Object(); - offsets.x = offsets.y = 0; + if (!offsets) { + offsets = new Object(); + offsets.x = offsets.y = 0; } if (typeof object === "string") - object = document.getElementById(object); + object = document.getElementById(object); offsets.x += object.offsetLeft; offsets.y += object.offsetTop; do { - object = object.offsetParent; - if (! object) - break; - offsets.x += object.offsetLeft; - offsets.y += object.offsetTop; - } while(object.tagName.toUpperCase() !== "BODY"); + object = object.offsetParent; + if (!object) + break; + offsets.x += object.offsetLeft; + offsets.y += object.offsetTop; + } while (object.tagName.toUpperCase() !== "BODY"); return offsets; -} + } function initFloatingSection() { var d = document.getElementById("console-section-container"); if (d === null) return; - window.onscroll = function() { + window.onscroll = function () { var offsets = getoffsets(d); var floatSection = d.childNodes[0]; @@ -70,19 +69,19 @@ document.addEventListener("DOMContentLoaded", function () { floatSection.className = "scrollAttached"; } } - } + }; } function loadOutline() { - if (outline !== null) return false; // already loaded + if (outline !== null) return false; // already loaded if (!loading) { loading = true; fetch( - rootURL+"/descriptor/org.jvnet.hudson.plugins.collapsingconsolesections.CollapsingSectionNote/outline" + rootURL + "/descriptor/org.jvnet.hudson.plugins.collapsingconsolesections.CollapsingSectionNote/outline", ).then( (resp) => { - resp.text().then( (responseText) => { + resp.text().then((responseText) => { const sidePanel = document.getElementById("side-panel"); sidePanel.insertAdjacentHTML("beforeend", responseText); @@ -90,96 +89,93 @@ document.addEventListener("DOMContentLoaded", function () { initFloatingSection(); loading = false; queue.forEach(handle); - }) - } + }); + }, ); } return true; } - function generateOutlineSection(sectionElt){ - - var id = "console-section-"+(iota++); - // add target link in output log + function generateOutlineSection(sectionElt) { + var id = "console-section-" + (iota++); + // add target link in output log var targetLink = document.createElement("a"); targetLink.name = id; sectionElt.prepend(targetLink); - // create outline element - var collapseHeader = sectionElt.querySelector("DIV.collapseHeader") - var elt = document.createElement("li") + // create outline element + var collapseHeader = sectionElt.querySelector("DIV.collapseHeader"); + var elt = document.createElement("li"); var link = document.createElement("a"); link.href = "#" + id; link.textContent = justtext(collapseHeader); elt.appendChild(link); - //check children sections - var level = -1; - var currentElement = sectionElt; - while (currentElement.closest("div.section")) { - currentElement = currentElement.closest("div.section").parentElement; - level++; - } - var childrenSections = sectionElt.querySelectorAll("div.section") + // check children sections + var level = -1; + var currentElement = sectionElt; + while (currentElement.closest("div.section")) { + currentElement = currentElement.closest("div.section").parentElement; + level++; + } + var childrenSections = sectionElt.querySelectorAll("div.section"); childrenSections = Array.from(childrenSections).filter( - function( section ) { - var parentLevel = -1; - var parentElement = section.closest("div.section").parentElement; - while (parentElement.closest("div.section")) { - parentElement = parentElement.closest("div.section").parentElement; - parentLevel++; - } - return parentLevel == level; - } - ) - if(childrenSections.length){ - var newParentUl = document.createElement("ul"); - newParentUl.dataset.name = "UL :"+sectionElt.dataset.level - childrenSections.forEach(function(child) { - var childElt = generateOutlineSection(child) - newParentUl.appendChild(childElt) - }); - elt.appendChild(newParentUl); + function (section) { + var parentLevel = -1; + var parentElement = section.closest("div.section").parentElement; + while (parentElement.closest("div.section")) { + parentElement = parentElement.closest("div.section").parentElement; + parentLevel++; + } + return parentLevel == level; + }, + ); + if (childrenSections.length) { + var newParentUl = document.createElement("ul"); + newParentUl.dataset.name = "UL :" + sectionElt.dataset.level; + childrenSections.forEach(function (child) { + var childElt = generateOutlineSection(child); + newParentUl.appendChild(childElt); + }); + elt.appendChild(newParentUl); } - return elt + return elt; } - - - function handle(e) { - var sectionElt = e; + + function handle(e) { + var sectionElt = e; if (loadOutline()) { - queue.push(e); - } else { - var newElt = generateOutlineSection(sectionElt) - outline.appendChild(newElt); + queue.push(e); + } else { + var newElt = generateOutlineSection(sectionElt); + outline.appendChild(newElt); } } - + function justtext(elt) { - - var clone = elt.cloneNode(true); - const childNodes = Array.from(clone.childNodes); - childNodes.forEach(node => { - if (node.nodeType === Node.ELEMENT_NODE) { - clone.removeChild(node); - } - }); - return clone.textContent; + var clone = elt.cloneNode(true); + const childNodes = Array.from(clone.childNodes); + childNodes.forEach((node) => { + if (node.nodeType === Node.ELEMENT_NODE) { + clone.removeChild(node); + } + }); + return clone.textContent; }; Behaviour.register({ // insert for each console section and put it into the outline - "div.section" : function(e) { - var level = -1; - var currentElement = e; - while (currentElement && currentElement.closest("div.section")) { - currentElement = currentElement.closest("div.section").parentElement; - level++; - } - //only treat top level section - if(level == 0){ - handle(e); - } - } + "div.section": function (e) { + var level = -1; + var currentElement = e; + while (currentElement && currentElement.closest("div.section")) { + currentElement = currentElement.closest("div.section").parentElement; + level++; + } + // only treat top level section + if (level == 0) { + handle(e); + } + }, }); });