From 9dfe5b288cfd26fdf0643bbf5a3e05bd3d3ff7ad Mon Sep 17 00:00:00 2001 From: Sergio Eduardo Castro Ceballos <72516762+SergioCasCeb@users.noreply.github.com> Date: Wed, 27 Mar 2024 00:37:03 +0100 Subject: [PATCH] Fixed all eslint issues with the web-new package, Modified the eslintrc.json file to a slightly newer version and to accept "module" scripts --- .eslintrc.json | 3 ++- packages/web-new/src/scripts/console.js | 27 +++++++++++----------- packages/web-new/src/scripts/editor.js | 2 +- packages/web-new/src/scripts/jsonld-vis.js | 8 +++---- packages/web-new/src/scripts/save-menu.js | 15 ++++++------ packages/web-new/tests/test.spec.js | 4 ++-- 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 1ee8a2848..4cf89a199 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -6,7 +6,8 @@ "jest": true }, "parserOptions": { - "ecmaVersion": 8 + "ecmaVersion": 2018, + "sourceType": "module" }, "extends": ["eslint:recommended", "prettier"], "ignorePatterns": ["dist", "node_modules", "bin"] diff --git a/packages/web-new/src/scripts/console.js b/packages/web-new/src/scripts/console.js index ca46cdb36..11d2ad864 100644 --- a/packages/web-new/src/scripts/console.js +++ b/packages/web-new/src/scripts/console.js @@ -146,7 +146,7 @@ visualizationOptions.forEach(option => { showConsoleError("This function is only allowed for Thing Descriptions!") } else { switch (option.id) { - case "open-api-tab": + case "open-api-tab": { if (fileType === "yaml") { openApiJsonBtn.disabled = false @@ -159,8 +159,8 @@ visualizationOptions.forEach(option => { enableAPIConversionWithProtocol(editorInstance) break; - - case "async-api-tab": + } + case "async-api-tab": { if (fileType === "yaml") { asyncApiJsonBtn.disabled = false asyncApiYamlBtn.disabled = true @@ -172,15 +172,15 @@ visualizationOptions.forEach(option => { enableAPIConversionWithProtocol(editorInstance) break; - - case "aas-tab": + } + case "aas-tab": { generateAAS(fileType, editorInstance) AASView.classList.remove("hidden") break; - - case "defaults-tab": + } + case "defaults-tab": { if (fileType === "yaml") { defaultsJsonBtn.disabled = false defaultsYamlBtn.disabled = true @@ -194,21 +194,22 @@ visualizationOptions.forEach(option => { defaultsView.classList.remove("hidden") break; - - case "visualize-tab": + } + case "visualize-tab": { visualize(td) break; - - case "validation-tab": + } + case "validation-tab": { validationView.classList.remove("hidden") const editorData = getEditorData(editorInstance) validate(editorData[1], editorValue) break; - - default: + } + default: { break; + } } } diff --git a/packages/web-new/src/scripts/editor.js b/packages/web-new/src/scripts/editor.js index 29a075aa3..461589d37 100644 --- a/packages/web-new/src/scripts/editor.js +++ b/packages/web-new/src/scripts/editor.js @@ -324,7 +324,7 @@ async function initEditor(ideNumber, editorValue, editorLanguage) { setFontSize(editorInstance) }) - editorInstance.getModel().onDidChangeContent(_ => { + editorInstance.getModel().onDidChangeContent(() => { try { const editorValues = getEditorData(editorInstance) diff --git a/packages/web-new/src/scripts/jsonld-vis.js b/packages/web-new/src/scripts/jsonld-vis.js index fc22f24ee..760f2058f 100644 --- a/packages/web-new/src/scripts/jsonld-vis.js +++ b/packages/web-new/src/scripts/jsonld-vis.js @@ -326,7 +326,7 @@ export function jsonldVis(jsonld, selector, config) { const nodeEnter = node.enter() .append('g') .attr('class', 'node') - .attr('transform', function (d) { return 'translate(' + source.y0 + ',' + source.x0 + ')'; }) + .attr('transform', function () { return 'translate(' + source.y0 + ',' + source.x0 + ')'; }) .on('click', click); nodeEnter.append('circle') @@ -389,7 +389,7 @@ export function jsonldVis(jsonld, selector, config) { const nodeExit = node.exit().transition() .duration(transitionDuration) .ease(transitionEase) - .attr('transform', function (d) { return 'translate(' + source.y + ',' + source.x + ')'; }) + .attr('transform', function () { return 'translate(' + source.y + ',' + source.x + ')'; }) .remove(); nodeExit.select('circle').attr('r', 0); @@ -400,7 +400,7 @@ export function jsonldVis(jsonld, selector, config) { link.enter().insert('path', 'g') .attr('class', 'link') - .attr('d', function (d) { + .attr('d', function () { const o = { x: source.x0, y: source.y0 }; return diagonal({ source: o, target: o }); }); @@ -413,7 +413,7 @@ export function jsonldVis(jsonld, selector, config) { link.exit().transition() .duration(transitionDuration) .ease(transitionEase) - .attr('d', function (d) { + .attr('d', function () { const o = { x: source.x, y: source.y }; return diagonal({ source: o, target: o }); }) diff --git a/packages/web-new/src/scripts/save-menu.js b/packages/web-new/src/scripts/save-menu.js index e883b3c4d..ef4a571bb 100644 --- a/packages/web-new/src/scripts/save-menu.js +++ b/packages/web-new/src/scripts/save-menu.js @@ -38,7 +38,7 @@ const downloadBtn = document.querySelector("#download-btn") // const saveAsBtn = document.querySelector("#save-as-btn") // const saveAsWarning = document.querySelector(".save-warning") const saveMenuContainer = document.querySelector(".save-menu__container") -let fileHandle; +// let fileHandle; openUrlTab.disabled = true shareUrlContainer.value = "" @@ -160,6 +160,8 @@ downloadBtn.addEventListener("click", () => { openUrlTab.disabled = true }) + +//TODO: Uncomment when https is implemented /* Save as btn functionality */ // saveAsBtn.addEventListener("click", () => { // saveAsFile() @@ -169,13 +171,12 @@ downloadBtn.addEventListener("click", () => { * Saves the td as a file in the file system * @param {*} content */ -async function saveFileInSystem(content) { - let stream = await fileHandle.createWritable() - await stream.write(content) - await stream.close() -} +// async function saveFileInSystem(content) { +// let stream = await fileHandle.createWritable() +// await stream.write(content) +// await stream.close() +// } -//TODO: Uncomment when https is implemented /** * Opens the file system allows the user to input a file * name and save it as json , jsonld or yaml diff --git a/packages/web-new/tests/test.spec.js b/packages/web-new/tests/test.spec.js index 086dca0b4..e6110f30a 100644 --- a/packages/web-new/tests/test.spec.js +++ b/packages/web-new/tests/test.spec.js @@ -1007,7 +1007,7 @@ test.describe("OpenAPI view functionality", () => { const openAPIContainer = openAPIEditor.getByRole('code').locator('div').filter({ hasText: '"openapi": "3.0.3",' }).nth(4) await expect(openAPIEditor).toHaveAttribute('data-mode-id', "json") - await expect(openAPIContainer).toHaveText('\"openapi\": \"3.0.3\",') + await expect(openAPIContainer).toHaveText('"openapi": "3.0.3",') const openAPIJsonBtn = page.locator('#open-api-json') @@ -1160,7 +1160,7 @@ test.describe("OpenAPI view functionality", () => { const openAPIContainer = openAPIEditor.getByRole('code').locator('div').filter({ hasText: '"openapi": "3.0.3",' }).nth(4) await expect(openAPIEditor).toHaveAttribute('data-mode-id', "json") - await expect(openAPIContainer).toHaveText('\"openapi\": \"3.0.3\",') + await expect(openAPIContainer).toHaveText('"openapi": "3.0.3",') const openAPIJsonBtn = page.locator('#open-api-json') await expect(openAPIJsonBtn).toBeDisabled()