From 85601d9853607a9af001f58704ab495f87b177fb Mon Sep 17 00:00:00 2001 From: DariusZdroba Date: Thu, 21 Nov 2024 17:26:18 +0200 Subject: [PATCH] chore: removed unnecessary file and toggle code ignore --- .../codeSuggestionWebviewScriptLS.ts | 1 + .../iacSuggestionWebviewProvider.ts | 3 +- .../suggestion/iacSuggestionWebviewScript.ts | 180 ------------------ 3 files changed, 3 insertions(+), 181 deletions(-) delete mode 100644 src/snyk/snykIac/views/suggestion/iacSuggestionWebviewScript.ts diff --git a/src/snyk/snykCode/views/suggestion/codeSuggestionWebviewScriptLS.ts b/src/snyk/snykCode/views/suggestion/codeSuggestionWebviewScriptLS.ts index 97999ba31..4eaec9940 100644 --- a/src/snyk/snykCode/views/suggestion/codeSuggestionWebviewScriptLS.ts +++ b/src/snyk/snykCode/views/suggestion/codeSuggestionWebviewScriptLS.ts @@ -215,6 +215,7 @@ declare const acquireVsCodeApi: any; const ignoreContainerElements = document.getElementsByClassName('ignore-action-container'); if (ignoreContainerElements) { + toggleElement((ignoreContainerElements[0] as HTMLElement), "show"); (ignoreContainerElements[0] as HTMLElement).style.display = suggestion?.showInlineIgnoresButton ? 'block' : 'none'; } diff --git a/src/snyk/snykIac/views/suggestion/iacSuggestionWebviewProvider.ts b/src/snyk/snykIac/views/suggestion/iacSuggestionWebviewProvider.ts index b3c0a166c..7cdd26338 100644 --- a/src/snyk/snykIac/views/suggestion/iacSuggestionWebviewProvider.ts +++ b/src/snyk/snykIac/views/suggestion/iacSuggestionWebviewProvider.ts @@ -107,9 +107,10 @@ export class IacSuggestionWebviewProvider // data-ide-style is a placeholder defined in the Language Server // to be replaced with the custom IDE styles. html = html.replace( - '', + '${ideStyle}', ``, ); + html = html.replace("${ideScript}", ""); return html; } diff --git a/src/snyk/snykIac/views/suggestion/iacSuggestionWebviewScript.ts b/src/snyk/snykIac/views/suggestion/iacSuggestionWebviewScript.ts deleted file mode 100644 index 320e1c990..000000000 --- a/src/snyk/snykIac/views/suggestion/iacSuggestionWebviewScript.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/// -// This script will be run within the webview itself -// It cannot access the main VS Code APIs directly. -(function () { - // TODO: Redefine types until bundling is introduced into extension - // https://stackoverflow.com/a/56938089/1713082 - type ConfigurationIssue = { - id: string; - title: string; - severity: string; - filePath: string; - additionalData: IacIssueData; - }; - type IacIssueData = { - publicId: string; - documentation: string; - lineNumber: number; - issue: string; - impact: string; - path?: string[]; - resolve?: string; - references?: string[]; - customUIContent: string; - }; - - let issue = {} as ConfigurationIssue; - const vscode = acquireVsCodeApi(); - - function navigateToUrl(url: string) { - vscode.postMessage({ - type: 'openBrowser', - value: url, - }); - } - - function showCurrentSuggestion() { - const severity = document.querySelector('.severity')!; - const title = document.querySelector('.suggestion .suggestion-text')!; - - // Set title - title.innerHTML = issue.title; - - // Set severity icon - setSeverityIcon(); - - // Fill identifiers line - fillIdentifiers(); - - // Fill description - fillDescription(); - - // Fill impact - fillImpact(); - - // Fill path - fillPath(); - - // Fill remediation - fillRemediation(); - - // Fill references - fillReferences(); - - function setSeverityIcon() { - if (issue.severity) { - severity.querySelectorAll('img').forEach(n => { - if (n.id.slice(-1) === 'l') { - if (n.id.includes(issue.severity)) n.className = 'icon light-only'; - else n.className = 'icon light-only hidden'; - } else { - if (n.id.includes(issue.severity)) n.className = 'icon dark-only'; - else n.className = 'icon dark-only hidden'; - } - }); - } else { - severity.querySelectorAll('img').forEach(n => (n.className = 'icon hidden')); - } - } - - function fillIdentifiers() { - const identifiers = document.querySelector('.identifiers')!; - identifiers.innerHTML = ''; // reset node - const typeNode = document.createTextNode('Issue'); - identifiers.appendChild(typeNode); - - appendIdentifierSpan( - identifiers, - issue.additionalData.publicId.toUpperCase(), - issue.additionalData.documentation, - ); - } - - function fillDescription() { - const module = document.querySelector('.description > .content')!; - module.textContent = issue.additionalData.issue; - } - - function fillImpact() { - const module = document.querySelector('.impact > .content')!; - module.textContent = issue.additionalData.impact; - } - - function fillPath() { - const module = document.querySelector('.path > .content code')!; - if (issue.additionalData.path) { - module.textContent = issue.additionalData.path.join(' > '); - } else { - module.textContent = 'No path available.'; - } - } - - function fillRemediation() { - const module = document.querySelector('.remediation')!; - if (issue.additionalData.resolve) { - module.textContent = issue.additionalData.resolve; - } else { - module.textContent = 'No remediation available.'; - } - } - - function fillReferences() { - const section = document.querySelector('.references')!; - if (issue.additionalData.references) { - section.classList.remove('hidden'); - const module = document.querySelector('.references > .reference-links')!; - for (const reference of issue.additionalData.references) { - const paragraph = document.createElement('p'); - const referenceLink = document.createElement('a'); - const linkText = document.createTextNode(reference); - referenceLink.appendChild(linkText); - referenceLink.title = reference; - referenceLink.onclick = () => navigateToUrl(reference); - paragraph.appendChild(referenceLink); - module.appendChild(paragraph); - } - } - } - } - - // file deepcode ignore InsufficientPostmessageValidation: Content Security Policy applied in provider - window.addEventListener('message', event => { - const { type, args } = event.data; - switch (type) { - case 'set': { - issue = args; - vscode.setState({ ...vscode.getState(), issue }); - showCurrentSuggestion(); - break; - } - case 'get': { - issue = vscode.getState()?.issue || {}; - showCurrentSuggestion(); - break; - } - } - }); - - function appendIdentifierSpan(identifiers: Element, id: string, link?: string) { - const delimiter = document.createElement('span'); - delimiter.className = 'delimiter'; - identifiers.appendChild(delimiter); - - let cveNode: HTMLElement; - if (link) { - cveNode = document.createElement('a'); - cveNode.onclick = () => navigateToUrl(link); - } else { - cveNode = document.createElement('span'); - } - - cveNode.innerText = id; - - identifiers.appendChild(cveNode); - } -})();