Skip to content

Commit

Permalink
fix: add wrapping to fix alignment of text
Browse files Browse the repository at this point in the history
  • Loading branch information
lwywoo committed Aug 15, 2019
1 parent 9c5d895 commit fb82ebb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -55,6 +55,7 @@
"@types/agent-base": "^4.2.0",
"abbrev": "^1.1.1",
"ansi-escapes": "3.2.0",
"wrap-ansi": "6.0.0",
"chalk": "^2.4.2",
"configstore": "^3.1.2",
"debug": "^3.1.0",
Expand Down
4 changes: 3 additions & 1 deletion src/cli/commands/test/formatters/legacy-format-issue.ts
@@ -1,5 +1,6 @@
import * as _ from 'lodash';
import chalk from 'chalk';
import * as wrap from 'wrap-ansi';
import * as config from '../../../../lib/config';
import {Options, TestOptions} from '../../../../lib/types';
import {isLocalFolder} from '../../../../lib/detect';
Expand Down Expand Up @@ -42,7 +43,8 @@ export function formatIssues(vuln: GroupedVuln, options: Options & TestOptions)
: '',
fixedIn: options.docker ? createFixedInText(vuln) : '',
dockerfilePackage: options.docker ? dockerfileInstructionText(vuln) : '',
legalInstructions: vuln.legalInstructions ? chalk.bold('\n Legal instructions: ' + vuln.legalInstructions) : '',
legalInstructions: vuln.legalInstructions ? chalk.bold('\n Legal instructions:\n '
+ wrap(vuln.legalInstructions, 100).split('\n').join('\n ')) : '',
};

return (
Expand Down
37 changes: 23 additions & 14 deletions src/cli/commands/test/formatters/remediation-based-format-issues.ts
@@ -1,9 +1,16 @@
import * as _ from 'lodash';
import chalk from 'chalk';
import * as wrap from 'wrap-ansi';
import * as config from '../../../../lib/config';
import { TestOptions } from '../../../../lib/types';
import { RemediationResult, PatchRemediation,
DependencyUpdates, IssueData, SEVERITY, GroupedVuln } from '../../../../lib/snyk-test/legacy';
import {
RemediationResult,
PatchRemediation,
DependencyUpdates,
IssueData,
SEVERITY,
GroupedVuln,
} from '../../../../lib/snyk-test/legacy';

interface BasicVulnInfo {
title: string;
Expand All @@ -19,7 +26,7 @@ export function formatIssuesWithRemediation(
vulns: GroupedVuln[],
remediationInfo: RemediationResult,
options: TestOptions,
): string[] {
): string[] {

const basicVulnInfo: {
[name: string]: BasicVulnInfo,
Expand Down Expand Up @@ -65,7 +72,7 @@ function constructPatchesText(
basicVulnInfo: {
[name: string]: BasicVulnInfo;
},
): string[] {
): string[] {

if (!(Object.keys(patches).length > 0)) {
return [];
Expand Down Expand Up @@ -94,7 +101,7 @@ function constructUpgradesText(
basicVulnInfo: {
[name: string]: BasicVulnInfo;
},
): string[] {
): string[] {

if (!(Object.keys(upgrades).length > 0)) {
return [];
Expand All @@ -105,15 +112,15 @@ function constructUpgradesText(
const upgradeDepTo = _.get(upgrades, [upgrade, 'upgradeTo']);
const vulnIds = _.get(upgrades, [upgrade, 'vulns']);
const upgradeText =
`\n Upgrade ${chalk.bold.whiteBright(upgrade)} to ${chalk.bold.whiteBright(upgradeDepTo)} to fix\n`;
`\n Upgrade ${chalk.bold.whiteBright(upgrade)} to ${chalk.bold.whiteBright(upgradeDepTo)} to fix\n`;
const thisUpgradeFixes = vulnIds
.map((id) => formatIssue(
id,
basicVulnInfo[id].title,
basicVulnInfo[id].severity,
basicVulnInfo[id].isNew,
`${basicVulnInfo[id].name}@${basicVulnInfo[id].version}`,
basicVulnInfo[id].legalInstructions))
id,
basicVulnInfo[id].title,
basicVulnInfo[id].severity,
basicVulnInfo[id].isNew,
`${basicVulnInfo[id].name}@${basicVulnInfo[id].version}`,
basicVulnInfo[id].legalInstructions))
.join('\n');
upgradeTextArray.push(upgradeText + thisUpgradeFixes);
}
Expand Down Expand Up @@ -168,11 +175,13 @@ function formatIssue(
};
const newBadge = isNew ? ' (new)' : '';
const name = vulnerableModule ? ` in ${chalk.bold(vulnerableModule)}` : '';
const wrapLegalText = wrap(`${legalInstructions}`, 100);
const formatLegalText = wrapLegalText.split('\n').join('\n ');

return severitiesColourMapping[severity].colorFunc(
` ✗ ${chalk.bold(title)}${newBadge} [${titleCaseText(severity)} Severity]`,
) + `[${config.ROOT}/vuln/${id}]` + name
+ (legalInstructions ? `${chalk.bold('\nLegal instructions')}: ${legalInstructions}` : '') ;
) + `[${config.ROOT}/vuln/${id}]` + name
+ (legalInstructions ? `${chalk.bold('\n Legal instructions')}:\n ${formatLegalText}` : '');
}

function titleCaseText(text) {
Expand Down

0 comments on commit fb82ebb

Please sign in to comment.