Use null-aware accessors in getResult

This commit is contained in:
Asger F
2022-10-21 13:56:30 +02:00
parent 53bb9d797b
commit 65777b5e60

View File

@@ -40,10 +40,7 @@ export type ResultKey = Result | Path | PathNode;
* Looks up a specific result in a result set.
*/
export function getResult(sarif: sarif.Log, key: Result | Path | PathNode): sarif.Result | undefined {
if (sarif.runs.length === 0) return undefined;
if (sarif.runs[0].results === undefined) return undefined;
const results = sarif.runs[0].results;
return results[key.resultIndex];
return sarif.runs[0]?.results?.[key.resultIndex];
}
/**