@snyk/code-client
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -5,4 +5,4 @@ "use strict"; | ||
function getSarif(analysisResults) { | ||
const { tool, suggestions } = getTools(analysisResults, getSuggestions(analysisResults)); | ||
const results = getResults(suggestions); | ||
const allIssuesBySuggestion = getSuggestions(analysisResults); | ||
const { rules, allIssues } = getRulesAndAllIssues(analysisResults, allIssuesBySuggestion); | ||
return { | ||
@@ -13,4 +13,4 @@ $schema: 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json', | ||
{ | ||
tool, | ||
results, | ||
tool: getTool(rules), | ||
results: getResults(allIssues), | ||
properties: { | ||
@@ -24,19 +24,20 @@ coverage: analysisResults.coverage, | ||
exports.default = getSarif; | ||
const getSuggestions = (analysisResults) => { | ||
function getSuggestions(analysisResults) { | ||
const suggestions = {}; | ||
for (const [file] of Object.entries(analysisResults.files)) { | ||
for (const [issueId, issues] of Object.entries(analysisResults.files[file])) { | ||
if (!suggestions || !Object.keys(suggestions).includes(issueId)) { | ||
suggestions[issueId] = { ...issues[0], file: file.substring(1) }; | ||
if (!Object.keys(suggestions).includes(issueId)) { | ||
suggestions[issueId] = []; | ||
} | ||
suggestions[issueId].push({ ...issues[0], file: file.substring(1) }); | ||
} | ||
} | ||
return suggestions; | ||
}; | ||
const getTools = (analysisResults, suggestions) => { | ||
} | ||
; | ||
function getRulesAndAllIssues(analysisResults, allIssuesBySuggestions) { | ||
var _a; | ||
const output = { driver: { name: 'SnykCode', semanticVersion: '1.0.0', version: '1.0.0' } }; | ||
let ruleIndex = 0; | ||
const rules = []; | ||
let ruleIndex = 0; | ||
const result = {}; | ||
const allIssues = []; | ||
for (const [suggestionIndex, suggestion] of Object.entries(analysisResults.suggestions)) { | ||
@@ -77,25 +78,29 @@ const severity = { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
result[suggestionIndex] = { | ||
...suggestions[suggestionIndex], | ||
ruleIndex, | ||
rule, | ||
level: severity, | ||
id: suggestionId, | ||
text: suggestion.message, | ||
}; | ||
const allIssuesOfSuggestion = allIssuesBySuggestions[suggestionIndex]; | ||
allIssuesOfSuggestion.forEach(issue => { | ||
allIssues.push({ | ||
...issue, | ||
ruleIndex, | ||
rule, | ||
level: severity, | ||
id: suggestionId, | ||
text: suggestion.message, | ||
}); | ||
}); | ||
ruleIndex += 1; | ||
} | ||
return { tool: { driver: { ...output.driver, rules } }, suggestions: result }; | ||
}; | ||
function getResults(suggestions) { | ||
return { rules, allIssues }; | ||
} | ||
; | ||
function getResults(allIssues) { | ||
const output = []; | ||
for (const [, suggestion] of Object.entries(suggestions)) { | ||
for (const issue of allIssues) { | ||
let helpers = []; | ||
let result = { | ||
ruleId: suggestion.id, | ||
ruleIndex: suggestion.ruleIndex, | ||
level: suggestion.level ? suggestion.level : 'none', | ||
ruleId: issue.id, | ||
ruleIndex: issue.ruleIndex, | ||
level: issue.level ? issue.level : 'none', | ||
message: { | ||
text: suggestion.text, | ||
markdown: suggestion.text, | ||
text: issue.text, | ||
markdown: issue.text, | ||
arguments: [''], | ||
@@ -107,10 +112,10 @@ }, | ||
artifactLocation: { | ||
uri: suggestion.file, | ||
uri: issue.file, | ||
uriBaseId: '%SRCROOT%', | ||
}, | ||
region: { | ||
startLine: suggestion.rows[0], | ||
endLine: suggestion.rows[1], | ||
startColumn: suggestion.cols[0], | ||
endColumn: suggestion.cols[1], | ||
startLine: issue.rows[0], | ||
endLine: issue.rows[1], | ||
startColumn: issue.cols[0], | ||
endColumn: issue.cols[1], | ||
}, | ||
@@ -121,5 +126,5 @@ }, | ||
}; | ||
if (suggestion.fingerprints) { | ||
if (issue.fingerprints) { | ||
result.fingerprints = {}; | ||
suggestion.fingerprints.forEach(fingerprinting => { | ||
issue.fingerprints.forEach(fingerprinting => { | ||
result.fingerprints[`${fingerprinting.version}`] = fingerprinting.fingerprint; | ||
@@ -130,4 +135,4 @@ }); | ||
let i = 0; | ||
if (suggestion.markers && suggestion.markers.length >= 1) { | ||
for (const marker of suggestion.markers) { | ||
if (issue.markers && issue.markers.length >= 1) { | ||
for (const marker of issue.markers) { | ||
for (const position of marker.pos) { | ||
@@ -168,10 +173,10 @@ const helperIndex = helpers.findIndex(helper => helper.msg === marker.msg); | ||
artifactLocation: { | ||
uri: suggestion.file, | ||
uri: issue.file, | ||
uriBaseId: '%SRCROOT%', | ||
}, | ||
region: { | ||
startLine: suggestion.rows[0], | ||
endLine: suggestion.rows[1], | ||
startColumn: suggestion.cols[0], | ||
endColumn: suggestion.cols[1], | ||
startLine: issue.rows[0], | ||
endLine: issue.rows[1], | ||
startColumn: issue.cols[0], | ||
endColumn: issue.cols[1], | ||
}, | ||
@@ -230,2 +235,6 @@ }, | ||
exports.getArgumentsAndMessage = getArgumentsAndMessage; | ||
function getTool(rules) { | ||
const output = { driver: { name: 'SnykCode', semanticVersion: '1.0.0', version: '1.0.0' } }; | ||
return { driver: { ...output.driver, rules } }; | ||
} | ||
//# sourceMappingURL=sarif_converter.js.map |
@@ -73,3 +73,3 @@ { | ||
}, | ||
"version": "3.1.1" | ||
"version": "3.1.2" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
135198
1956