Skip to content

Commit

Permalink
applying code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagobcx committed Aug 29, 2024
1 parent ca59757 commit 3f63566
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
30 changes: 15 additions & 15 deletions src/models/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ export class AstResult extends CxResult {

getIcon() {
switch (this.severity) {
case "CRITICAL":
case constants.criticalSeverity:
return path.join("media", "icons", "critical_untoggle.svg");
case "HIGH":
case constants.highSeverity:
return path.join("media", "icons", "high_untoggle.svg");
case "MEDIUM":
case constants.mediumSeverity:
return path.join("media", "icons", "medium_untoggle.svg");
case "INFO":
case constants.infoSeverity:
return path.join("media", "icons", "info_untoggle.svg");
case "LOW":
case constants.lowSeverity:
return path.join("media", "icons", "low_untoggle.svg");
}
return "";
Expand Down Expand Up @@ -178,31 +178,31 @@ export class AstResult extends CxResult {

getSeverityCode() {
switch (this.severity) {
case "CRITICAL":
case constants.criticalSeverity:
return vscode.DiagnosticSeverity.Error;
case "HIGH":
case constants.highSeverity:
return vscode.DiagnosticSeverity.Error;
case "MEDIUM":
case constants.mediumSeverity:
return vscode.DiagnosticSeverity.Warning;
case "INFO":
case constants.infoSeverity:
return vscode.DiagnosticSeverity.Information;
case "LOW":
case constants.infoSeverity:
return vscode.DiagnosticSeverity.Information;
}
return vscode.DiagnosticSeverity.Information;
}

getSeverity() {
switch (this.severity) {
case "CRITICAL":
case constants.criticalSeverity:
return SeverityLevel.critical;
case "HIGH":
case constants.highSeverity:
return SeverityLevel.high;
case "MEDIUM":
case constants.mediumSeverity:
return SeverityLevel.medium;
case "INFO":
case constants.infoSeverity:
return SeverityLevel.info;
case "LOW":
case constants.lowSeverity:
return SeverityLevel.low;
}
return SeverityLevel.empty;
Expand Down
10 changes: 8 additions & 2 deletions src/utils/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,14 @@ export const constants = {
vorpalStart: "Vorpal engine started",
vorpalDisabled: "Vorpal Real-time Scanning is disabled now.",
vorpalEngineName: "Vorpal",
ActivateVorpalAutoScanning:"Activate Vorpal Real-time Scanning",
CheckmarxVorpal:"CheckmarxVorpal",
ActivateVorpalAutoScanning: "Activate Vorpal Real-time Scanning",
CheckmarxVorpal: "CheckmarxVorpal",

criticalSeverity: "CRITICAL",
highSeverity: "HIGH",
mediumSeverity: "MEDIUM",
lowSeverity: "LOW",
infoSeverity: "INFO",
};

export enum GroupBy {
Expand Down
16 changes: 8 additions & 8 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ export function getFormattedDateTime(createdAt: string) {
}

export function getFormattedId(label: CxScan, scanList: CxScan[]) {
if (scanList === null || scanList === undefined || scanList.length === 0){
if (scanList === null || scanList === undefined || scanList.length === 0) {
return "";
}
}

return label === scanList[0]
? label.id + " (latest)"
: label.id;
? label.id + " (latest)"
: label.id;
}

export function formatLabel(label: CxScan, scanList: CxScan[]) {
return label === scanList[0]
? getScanLabel(label.createdAt, label.id) + " (latest)"
: getScanLabel(label.createdAt, label.id);
? getScanLabel(label.createdAt, label.id) + " (latest)"
: getScanLabel(label.createdAt, label.id);
}

export async function enableButton(button: string) {
Expand Down Expand Up @@ -162,7 +162,7 @@ export function readResultsFromFile(resultJsonPath: string, scan: string): CxRes
.readFileSync(resultJsonPath, "utf-8")
.replace(/:([0-9]{15,}),/g, ':"$1",')
);
if(jsonResults.results){
if (jsonResults.results) {
results = orderResults(jsonResults.results);
}
else {
Expand All @@ -173,7 +173,7 @@ export function readResultsFromFile(resultJsonPath: string, scan: string): CxRes
}

export function orderResults(list: CxResult[]): CxResult[] {
const order = ["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"];
const order = [constants.criticalSeverity, constants.highSeverity, constants.mediumSeverity, constants.lowSeverity, constants.infoSeverity];
return list.sort(
(a, b) => order.indexOf(a.severity) - order.indexOf(b.severity)
);
Expand Down

0 comments on commit 3f63566

Please sign in to comment.