diff --git a/src/cli/commands/protect/prompts.ts b/src/cli/commands/protect/prompts.ts index 8abe6edac2..31a368db77 100644 --- a/src/cli/commands/protect/prompts.ts +++ b/src/cli/commands/protect/prompts.ts @@ -20,10 +20,7 @@ import * as config from '../../../lib/config'; import * as snykPolicy from 'snyk-policy'; import chalk from 'chalk'; import { AnnotatedIssue, SEVERITY } from '../../../lib/snyk-test/legacy'; -import { - legacySeveritiesColourMapping, - defaultSeverityColor, -} from '../../../lib/snyk-test/common'; +import { getLegacySeveritiesColour } from '../../../lib/snyk-test/common'; import { titleCaseText } from '../test/formatters/legacy-format-issue'; const debug = debugModule('snyk'); @@ -50,9 +47,7 @@ function sort(prop) { function createSeverityBasedIssueHeading(msg: string, severity: SEVERITY) { // Example: ✗ Medium severity vulnerability found in xmldom - const severityColor = legacySeveritiesColourMapping[severity] - ? legacySeveritiesColourMapping[severity] - : defaultSeverityColor; + const severityColor = getLegacySeveritiesColour(severity); return severityColor.colorFunc(msg); } diff --git a/src/cli/commands/test/formatters/legacy-format-issue.ts b/src/cli/commands/test/formatters/legacy-format-issue.ts index 8be1033761..fb348d1ac3 100644 --- a/src/cli/commands/test/formatters/legacy-format-issue.ts +++ b/src/cli/commands/test/formatters/legacy-format-issue.ts @@ -18,10 +18,7 @@ import { import { formatLegalInstructions } from './legal-license-instructions'; import { getReachabilityText } from './format-reachability'; import { PATH_SEPARATOR } from '../../constants'; -import { - legacySeveritiesColourMapping, - defaultSeverityColor, -} from '../../../../lib/snyk-test/common'; +import { getLegacySeveritiesColour } from '../../../../lib/snyk-test/common'; export function formatIssues( vuln: GroupedVuln, @@ -99,9 +96,7 @@ function createSeverityBasedIssueHeading({ }: CreateSeverityBasedIssueHeading) { // Example: ✗ Medium severity vulnerability found in xmldom const vulnTypeText = type === 'license' ? 'issue' : 'vulnerability'; - const severityColor = legacySeveritiesColourMapping[severity] - ? legacySeveritiesColourMapping[severity] - : defaultSeverityColor; + const severityColor = getLegacySeveritiesColour(severity); let originalSeverityStr = ''; if (originalSeverity && originalSeverity !== severity) { diff --git a/src/cli/commands/test/formatters/remediation-based-format-issues.ts b/src/cli/commands/test/formatters/remediation-based-format-issues.ts index 34b2a85649..7c0f5a6b2a 100644 --- a/src/cli/commands/test/formatters/remediation-based-format-issues.ts +++ b/src/cli/commands/test/formatters/remediation-based-format-issues.ts @@ -16,8 +16,7 @@ import { } from '../../../../lib/snyk-test/legacy'; import { SEVERITIES, - severitiesColourMapping, - defaultSeverityColor, + getSeveritiesColour, } from '../../../../lib/snyk-test/common'; import { formatLegalInstructions } from './legal-license-instructions'; import { @@ -442,9 +441,7 @@ export function formatIssue( reachability?: REACHABILITY, sampleReachablePaths?: SampleReachablePaths, ): string { - const severityColor = severitiesColourMapping[severity] - ? severitiesColourMapping[severity] - : defaultSeverityColor; + const severityColor = getSeveritiesColour(severity); const newBadge = isNew ? ' (new)' : ''; const name = vulnerableModule ? ` in ${chalk.bold(vulnerableModule)}` : ''; diff --git a/src/cli/commands/test/iac-output.ts b/src/cli/commands/test/iac-output.ts index d654ed4594..bba45c02ba 100644 --- a/src/cli/commands/test/iac-output.ts +++ b/src/cli/commands/test/iac-output.ts @@ -10,10 +10,7 @@ import { printPath } from './formatters/remediation-based-format-issues'; import { titleCaseText } from './formatters/legacy-format-issue'; import * as sarif from 'sarif'; import { SEVERITY } from '../../../lib/snyk-test/legacy'; -import { - severitiesColourMapping, - defaultSeverityColor, -} from '../../../lib/snyk-test/common'; +import { getSeveritiesColour } from '../../../lib/snyk-test/common'; import { IacFileInDirectory } from '../../../lib/types'; import upperFirst = require('lodash.upperfirst'); const debug = Debug('iac-output'); @@ -35,9 +32,7 @@ function formatIacIssue( const description = extractOverview(issue.description).trim(); const descriptionLine = `\n ${description}\n`; - const severityColor = severitiesColourMapping[issue.severity] - ? severitiesColourMapping[issue.severity] - : defaultSeverityColor; + const severityColor = getSeveritiesColour(issue.severity); return ( severityColor.colorFunc( diff --git a/src/lib/snyk-test/common.ts b/src/lib/snyk-test/common.ts index b8bb757871..aaee849c2b 100644 --- a/src/lib/snyk-test/common.ts +++ b/src/lib/snyk-test/common.ts @@ -101,6 +101,14 @@ export const defaultSeverityColor = { }, }; +export function getSeveritiesColour(severity: string) { + return severitiesColourMapping[severity] || defaultSeverityColor; +} + +export function getLegacySeveritiesColour(severity: string) { + return legacySeveritiesColourMapping[severity] || defaultSeverityColor; +} + export enum FAIL_ON { all = 'all', upgradable = 'upgradable',