Skip to content

Commit

Permalink
fix: correct Code analysis return type
Browse files Browse the repository at this point in the history
  • Loading branch information
novalex committed Feb 20, 2023
1 parent 1a1717a commit 3b27517
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/lib/plugins/sast/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import {
analyzeFolders,
AnalysisSeverity,
MAX_FILE_SIZE,
FileAnalysis,
AnalysisResultSarif,
} from '@snyk/code-client';
import { ReportingDescriptor, Result } from 'sarif';
import { SEVERITY } from '../../snyk-test/legacy';
import { getAuthHeader } from '../../api-token';
import config from '../../config';
import { spinner } from '../../spinner';
import { Options } from '../../types';
import { SastSettings, Log, CodeTestResults } from './types';
import {
SastSettings,
Log,
CodeTestResults,
CodeAnalysisResults,
} from './types';
import { analysisProgressUpdate } from './utils';
import {
FeatureNotSupportedBySnykCodeError,
Expand Down Expand Up @@ -47,7 +50,7 @@ export async function getCodeTestResults(

return {
reportResults: codeAnalysis.reportResults,
analysisResults: codeAnalysis.analysisResults as AnalysisResultSarif,
analysisResults: codeAnalysis.analysisResults,
};
}

Expand All @@ -56,7 +59,7 @@ async function getCodeAnalysis(
options: Options,
sastSettings: SastSettings,
requestId: string,
): Promise<FileAnalysis | null> {
) {
const isLocalCodeEngineEnabled = isLocalCodeEngine(sastSettings);
if (isLocalCodeEngineEnabled) {
validateLocalCodeEngineUrl(sastSettings.localCodeEngine.url);
Expand Down Expand Up @@ -132,7 +135,7 @@ async function getCodeAnalysis(
);
}

if (!result || result?.analysisResults.type !== 'sarif') {
if (!result || result.analysisResults.type !== 'sarif') {
return null;
}

Expand All @@ -147,7 +150,7 @@ async function getCodeAnalysis(
);
}

return result;
return result as CodeAnalysisResults;
}

function filterIgnoredIssues(codeAnalysis: Log): Log {
Expand Down
10 changes: 9 additions & 1 deletion src/lib/plugins/sast/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export { Log, Tool, Result } from 'sarif';
import { AnalysisResultSarif, ReportResult } from '@snyk/code-client';
import {
AnalysisResultSarif,
FileAnalysis,
ReportResult,
} from '@snyk/code-client';

interface LocalCodeEngine {
enabled: boolean;
Expand All @@ -26,3 +30,7 @@ export interface CodeTestResults {
reportResults?: ReportResult['uploadResult'];
analysisResults: AnalysisResultSarif;
}

export interface CodeAnalysisResults extends FileAnalysis {
analysisResults: AnalysisResultSarif;
}

0 comments on commit 3b27517

Please sign in to comment.