Skip to content

Commit

Permalink
SLVSCODE-891 new icons for standard severity mode
Browse files Browse the repository at this point in the history
* SLVSCODE-891 color SVGs using CSS
  • Loading branch information
sophio-japharidze-sonarsource authored Nov 25, 2024
1 parent f38f49f commit 60557c2
Show file tree
Hide file tree
Showing 28 changed files with 98 additions and 15 deletions.
Binary file removed images/3.8_selectFolder.png
Binary file not shown.
Binary file removed images/3.8_selectProject.png
Binary file not shown.
Binary file removed images/add-binding.png
Binary file not shown.
Binary file removed images/connected_mode_treeview.png
Binary file not shown.
Binary file removed images/connection_success.png
Binary file not shown.
Binary file removed images/create_view.png
Binary file not shown.
Binary file removed images/edit-binding.png
Binary file not shown.
Binary file removed images/severity/blocker.png
Binary file not shown.
3 changes: 3 additions & 0 deletions images/severity/blocker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/severity/critical.png
Binary file not shown.
3 changes: 3 additions & 0 deletions images/severity/critical.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/severity/info.png
Binary file not shown.
3 changes: 3 additions & 0 deletions images/severity/info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/severity/major.png
Binary file not shown.
3 changes: 3 additions & 0 deletions images/severity/major.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/severity/minor.png
Binary file not shown.
3 changes: 3 additions & 0 deletions images/severity/minor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/type/bug.png
Binary file not shown.
8 changes: 8 additions & 0 deletions images/type/bug.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/type/code_smell.png
Binary file not shown.
5 changes: 5 additions & 0 deletions images/type/code_smell.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/type/security_hotspot.png
Binary file not shown.
Binary file removed images/type/vulnerability.png
Binary file not shown.
5 changes: 5 additions & 0 deletions images/type/vulnerability.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@
"tar": "^7.2.0",
"underscore": "^1.13.6",
"vscode-languageclient": "^8.0.2",
"xmldom": "^0.6.0",
"zlib": "^1.0.5"
},
"devDependencies": {
Expand Down
34 changes: 24 additions & 10 deletions src/rules/rulepanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import * as util from '../util/util';
import { clean, escapeHtml, ResourceResolver } from '../util/webview';
import { decorateContextualHtmlContentWithDiff } from './code-diff';
import { highlightAllCodeSnippetsInDesc } from './syntax-highlight';
import * as fs from 'fs';
import { DOMParser, XMLSerializer } from 'xmldom';

let ruleDescriptionPanel: VSCode.WebviewPanel;

Expand Down Expand Up @@ -111,6 +113,27 @@ function renderImpact(softwareQuality: string, severity: string, resolver: Resou
</div>`;
}

function renderStandardModeSeverityDetails(ruleType: string, severity: string, resolver: ResourceResolver) {
const ruleTypeToLowerCase = ruleType.toLocaleLowerCase('en-us');
const severityToLowerCase = severity.toLocaleLowerCase('en-us');
const ruleTypeImgSrc = util.resolveExtensionFile('images', 'type', `${ruleTypeToLowerCase}.svg`);
const severityImgSrc = util.resolveExtensionFile('images', 'severity', `${severityToLowerCase}.svg`);
return `<div class="impact severity-${severityToLowerCase} capsule">
${fetchSVGIcon(ruleTypeImgSrc)}
&nbsp;${clean(ruleType)}&nbsp;
${fetchSVGIcon(severityImgSrc)}
</div>`;
}

function fetchSVGIcon(pathToSVG: VSCode.Uri) : string {
const svgText = fs.readFileSync(pathToSVG.path, 'utf8');
const parser : DOMParser = new DOMParser();
const svgDoc = parser.parseFromString(svgText, 'image/svg+xml');
const svgElement = svgDoc.documentElement;

return new XMLSerializer().serializeToString(svgElement);
}

function renderTaxonomyInfo(rule: ShowRuleDescriptionParams, resolver: ResourceResolver) {
if (rule.severityDetails.impacts && Object.keys(rule.severityDetails.impacts).length > 0) {
// Clean Code taxonomy
Expand All @@ -126,17 +149,8 @@ function renderTaxonomyInfo(rule: ShowRuleDescriptionParams, resolver: ResourceR
</div>`;
} else {
// Old type + severity taxonomy
const severityImgSrc = resolver.resolve('images', 'severity', `${rule.severityDetails.severity.toLowerCase()}.png`);
const typeImgSrc = resolver.resolve('images', 'type', `${rule.severityDetails.type.toLowerCase()}.png`);
return `<div class="taxonomy">
<div class="impact capsule">
${clean(rule.severityDetails.type)}
<img alt="${rule.severityDetails.type}" src="${typeImgSrc}" />
</div>
<div class="impact capsule">
${clean(rule.severityDetails.severity)}
<img alt="${rule.severityDetails.severity}" src="${severityImgSrc}" />
</div>
${renderStandardModeSeverityDetails(rule.severityDetails.type, rule.severityDetails.severity, resolver)}
</div>`;
}
}
Expand Down
35 changes: 30 additions & 5 deletions styles/rule.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,61 @@ a {
border: 1px solid;
}

.impact-blocker {
.impact-blocker, .severity-blocker {
color: var(--sonarlint-blocker-color);
background-color: var(--sonarlint-blocker-background-color);
border-color: var(--sonarlint-blocker-border-color);
}

.impact-high {
.impact-high, .severity-critical {
color: var(--sonarlint-high-color);
background-color: var(--sonarlint-high-background-color);
border-color: var(--sonarlint-high-border-color);
}

.impact-medium {
.impact-medium, .severity-major {
color: var(--sonarlint-medium-color);
background-color: var(--sonarlint-medium-background-color);
border-color: var(--sonarlint-medium-border-color);
}

.impact-low {
.impact-low, .severity-minor {
color: var(--sonarlint-low-color);
background-color: var(--sonarlint-low-background-color);
border-color: var(--sonarlint-low-border-color);
}

.impact-info {
.impact-info, .severity-info {
color: var(--sonarlint-info-color);
background-color: var(--sonarlint-info-background-color);
border-color: var(--sonarlint-info-border-color);
}

.severity-blocker svg {
fill: currentColor;
color: var(--sonarlint-blocker-border-color);
}

.severity-critical svg {
fill: currentColor;
color: var(--sonarlint-high-boder-color);
}

.severity-major svg {
fill: currentColor;
color: var(--sonarlint-medium-border-color);
}

.severity-minor svg {
fill: currentColor;
color: var(--sonarlint-low-border-color);
}

.severity-info svg {
fill: currentColor;
color: var(--sonarlint-info-border-color);
}

.impact img {
display: inline-block;
width: 16px;
Expand Down

0 comments on commit 60557c2

Please sign in to comment.