Skip to content

Commit a36c29d

Browse files
committed
Improve parsing of relative paths in tool results
1 parent 02540e9 commit a36c29d

4 files changed

Lines changed: 8 additions & 20 deletions

File tree

src/parsers/bandit.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import * as vscode from 'vscode';
44
import { ToolFinding } from '../models/toolFinding';
5+
import { relativePathToFull } from '../utils';
56

67
class BanditParser {
78
static parse(fileContent: string) {
@@ -11,11 +12,7 @@ class BanditParser {
1112
const banditFindings = JSON.parse(fileContent).results;
1213
banditFindings.map((banditFinding: any) => {
1314
// uri
14-
let fullPath = '';
15-
if (vscode.workspace.workspaceFolders) {
16-
fullPath = vscode.workspace.workspaceFolders[0].uri.fsPath + '/';
17-
}
18-
const uri = vscode.Uri.file(`${fullPath}${banditFinding.filename}`);
15+
const uri = vscode.Uri.file(relativePathToFull(banditFinding.filename));
1916

2017
// range
2118
const lineRange = banditFinding.line_range;

src/parsers/brakeman.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import * as vscode from 'vscode';
44
import { ToolFinding } from '../models/toolFinding';
5+
import { relativePathToFull } from '../utils';
56

67
class BrakemanParser {
78
static parse(fileContent: string) {
@@ -11,11 +12,7 @@ class BrakemanParser {
1112
const brakemanFindings = JSON.parse(fileContent).warnings;
1213
brakemanFindings.map((brakemanFinding: any) => {
1314
// uri
14-
let fullPath = '';
15-
if (vscode.workspace.workspaceFolders) {
16-
fullPath = vscode.workspace.workspaceFolders[0].uri.fsPath + '/';
17-
}
18-
const uri = vscode.Uri.file(`${fullPath}${brakemanFinding.file}`);
15+
const uri = vscode.Uri.file(relativePathToFull(brakemanFinding.file));
1916

2017
// range
2118
const range = new vscode.Range(

src/parsers/checkov.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import * as vscode from 'vscode';
44
import { ToolFinding } from '../models/toolFinding';
5+
import { relativePathToFull } from '../utils';
56

67
class CheckovParser {
78
static parse(fileContent: string) {
@@ -13,11 +14,7 @@ class CheckovParser {
1314
const checkovFindings = checkovCheckType.results.failed_checks;
1415
checkovFindings.map((checkovFinding: any) => {
1516
// uri
16-
let fullPath = '';
17-
if (vscode.workspace.workspaceFolders) {
18-
fullPath = vscode.workspace.workspaceFolders[0].uri.fsPath + '/';
19-
}
20-
const uri = vscode.Uri.file(`${fullPath}${checkovFinding.file_path}`);
17+
const uri = vscode.Uri.file(relativePathToFull(checkovFinding.file_path));
2118

2219
// range
2320
const range = new vscode.Range(

src/parsers/semgrep.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import * as vscode from 'vscode';
44
import { ToolFinding } from '../models/toolFinding';
5+
import { relativePathToFull } from '../utils';
56

67
class SemgrepParser {
78
static parse(fileContent: string) {
@@ -11,11 +12,7 @@ class SemgrepParser {
1112
const semgrepFindings = JSON.parse(fileContent).results;
1213
semgrepFindings.map((semgrepFinding: any) => {
1314
// uri
14-
let fullPath = '';
15-
if (vscode.workspace.workspaceFolders) {
16-
fullPath = vscode.workspace.workspaceFolders[0].uri.fsPath + '/';
17-
}
18-
const uri = vscode.Uri.file(`${fullPath}${semgrepFinding.path}`);
15+
const uri = vscode.Uri.file(relativePathToFull(semgrepFinding.path));
1916

2017
// range
2118
const range = new vscode.Range(

0 commit comments

Comments
 (0)