Skip to content

Commit

Permalink
feat: Centralize icons and err messages by theme
Browse files Browse the repository at this point in the history
  • Loading branch information
ofir-eldar-snyk authored and maxjeffos committed Jul 21, 2021
1 parent e3c3ac0 commit 3292ffb
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 30 deletions.
3 changes: 2 additions & 1 deletion scripts/check-dependencies.ts
Expand Up @@ -3,6 +3,7 @@ import * as fs from 'fs';
import * as path from 'path';
import * as glob from 'glob';
import { config } from '../check-dependencies.config';
import { icon } from '../src/lib/theme';

const checkDependencies = async () => {
let exitCode = 0;
Expand Down Expand Up @@ -55,7 +56,7 @@ const checkDependencies = async () => {
}
}
} else {
console.log('\n No problems found.');
console.log(`\n ${icon.VALID} No problems found.`);
}

console.log();
Expand Down
7 changes: 4 additions & 3 deletions src/cli/commands/fix/index.ts
Expand Up @@ -19,6 +19,7 @@ import { validateFixCommandIsSupported } from './validate-fix-command-is-support
import { Options, TestOptions } from '../../../lib/types';
import { getDisplayPath } from './get-display-path';
import chalk from 'chalk';
import { icon, color } from '../../../lib/theme';

const debug = Debug('snyk-fix');
const snykFixFeatureFlag = 'cliSnykFix';
Expand Down Expand Up @@ -135,16 +136,16 @@ async function runSnykTestLegacy(
results.push(...newRes);
stdOutSpinner.stopAndPersist({
text: spinnerMessage,
symbol: '\n►',
symbol: `\n${icon.RUN}`,
});
} catch (error) {
const testError = formatTestError(error);
const userMessage =
chalk.red(`Failed! ${testError.message}.`) +
color.status.error(`Failed! ${testError.message}.`) +
`\n Tip: run \`snyk test ${displayPath} -d\` for more information.`;
stdOutSpinner.stopAndPersist({
text: spinnerMessage,
symbol: '\n►',
symbol: `\n${icon.RUN}`,
});
stdErrSpinner.stopAndPersist({
text: userMessage,
Expand Down
7 changes: 4 additions & 3 deletions src/cli/commands/protect/prompts.ts
Expand Up @@ -19,6 +19,7 @@ import { parsePackageString as moduleToObject } from 'snyk-module';
import * as config from '../../../lib/config';
import * as snykPolicy from 'snyk-policy';
import chalk from 'chalk';
import { icon, color } from '../../../lib/theme';
import { AnnotatedIssue, SEVERITY } from '../../../lib/snyk-test/legacy';
import { colorTextBySeverity } from '../../../lib/snyk-test/common';
import { titleCaseText } from '../../../lib/formatters/legacy-format-issue';
Expand Down Expand Up @@ -617,7 +618,7 @@ function generatePrompt(
const joiningText = group.patch ? 'in' : 'via';
const issues = vuln.type === 'license' ? 'issues' : 'vulnerabilities';
messageIntro = fmt(
'✗ %s %s %s introduced %s %s',
`${icon.ISSUE} %s %s %s introduced %s %s`,
group.count,
`${severity}${originalSeverityStr}`,
issues,
Expand All @@ -631,7 +632,7 @@ function generatePrompt(
} else {
infoLink += chalk.underline('/vuln/' + vuln.id);
messageIntro = fmt(
'✗ %s severity %s found in %s, introduced via',
`${icon.ISSUE} %s severity %s found in %s, introduced via`,
`${severity}${originalSeverityStr}`,
vuln.type === 'license' ? 'issue' : 'vuln',
vulnIn,
Expand Down Expand Up @@ -760,7 +761,7 @@ function generatePrompt(
toPackageVersion,
);
let lead = '';
const breaking = chalk.red('potentially breaking change');
const breaking = color.status.error('potentially breaking change');
if (diff === 'major') {
lead = ' (' + breaking + ', ';
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/cli/commands/protect/wizard.ts
Expand Up @@ -39,6 +39,7 @@ import { ModuleInfo as moduleInfo } from '../../../lib/module-info';
import { MisconfiguredAuthInCI } from '../../../lib/errors/misconfigured-auth-in-ci-error';
import { MissingTargetFileError } from '../../../lib/errors/missing-targetfile-error';
import * as pm from '../../../lib/package-managers';
import { icon, color } from '../../../lib/theme';
import {
Options,
MonitorMeta,
Expand Down Expand Up @@ -192,9 +193,8 @@ async function processWizardFlow(options) {
);
} else {
console.log(
chalk.green(
'✓ Tested %s dependencies for known ' +
'vulnerabilities, no vulnerable paths found.',
color.status.success(
`${icon.VALID} Tested %s dependencies for known vulnerabilities, no vulnerable paths found.`,
),
res.dependencyCount,
);
Expand Down
5 changes: 2 additions & 3 deletions src/cli/commands/test/validate-test-options.ts
@@ -1,5 +1,4 @@
import chalk from 'chalk';

import { color } from '../../../lib/theme';
import { TestOptions, Options } from '../../../lib/types';
import { FAIL_ON, FailOn, SEVERITIES } from '../../../lib/snyk-test/common';
import { FailOnError } from '../../../lib/errors/fail-on-error.ts';
Expand All @@ -14,7 +13,7 @@ export function validateTestOptions(options: TestOptions & Options) {

if (options.failOn && !validateFailOn(options.failOn)) {
const error = new FailOnError();
throw chalk.red.bold(error.message);
throw color.status.error(error.message);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib/formatters/iac-output.ts
@@ -1,4 +1,5 @@
import chalk from 'chalk';
import { icon } from '../theme';
import * as Debug from 'debug';
import * as pathLib from 'path';
import { pathToFileURL } from 'url';
Expand Down Expand Up @@ -36,7 +37,7 @@ function formatIacIssue(
return (
colorTextBySeverity(
issue.severity,
` ${chalk.bold(issue.title)}${newBadge} [${titleCaseText(
` ${icon.ISSUE} ${chalk.bold(issue.title)}${newBadge} [${titleCaseText(
issue.severity,
)} Severity]`,
) +
Expand Down
3 changes: 2 additions & 1 deletion src/lib/formatters/remediation-based-format-issues.ts
@@ -1,4 +1,5 @@
import chalk from 'chalk';
import { icon } from '../theme';
import * as config from '../../lib/config';
import { TestOptions } from '../../lib/types';
import {
Expand Down Expand Up @@ -488,7 +489,7 @@ export function formatIssue(
return (
colorTextBySeverity(
severity,
` ${chalk.bold(title)}${newBadge} [${titleCaseText(
` ${icon.ISSUE} ${chalk.bold(title)}${newBadge} [${titleCaseText(
severity,
)} Severity${originalSeverityStr}]`,
) +
Expand Down
6 changes: 4 additions & 2 deletions src/lib/formatters/test/display-result.ts
@@ -1,6 +1,6 @@
import * as pathLib from 'path';
import chalk from 'chalk';

import { icon, color } from '../../theme';
import { isCI } from '../../../lib/is-ci';
import {
Options,
Expand Down Expand Up @@ -75,7 +75,9 @@ export function displayResult(
const vulnPathsText = options.showVulnPaths
? 'no vulnerable paths found.'
: 'none were found.';
const summaryOKText = chalk.green(`✓ ${testedInfoText}, ${vulnPathsText}`);
const summaryOKText = color.status.success(
`${icon.VALID} ${testedInfoText}, ${vulnPathsText}`,
);
const nextStepsText = localPackageTest
? '\n\nNext steps:' +
'\n- Run `snyk monitor` to be notified ' +
Expand Down
3 changes: 2 additions & 1 deletion src/lib/plugins/get-deps-from-plugin.ts
@@ -1,6 +1,7 @@
import * as debugModule from 'debug';
import * as pathLib from 'path';
import chalk from 'chalk';
import { icon } from '../theme';
import { legacyPlugin as pluginApi } from '@snyk/cli-interface';
import { find } from '../find-files';
import { Options, TestOptions, MonitorOptions } from '../types';
Expand Down Expand Up @@ -148,7 +149,7 @@ export function warnSomeGradleManifestsNotScanned(
',\n',
)}`,
);
return ` ${diff.length}/${detectedGradleFiles.length} detected Gradle manifests did not return dependencies. They may have errored or were not included as part of a multi-project build. You may need to scan them individually with --file=path/to/file. Run with \`-d\` for more info.`;
return `${icon.ISSUE} ${diff.length}/${detectedGradleFiles.length} detected Gradle manifests did not return dependencies. They may have errored or were not included as part of a multi-project build. You may need to scan them individually with --file=path/to/file. Run with \`-d\` for more info.`;
}
return null;
}
3 changes: 2 additions & 1 deletion src/lib/plugins/get-multi-plugin-result.ts
Expand Up @@ -2,6 +2,7 @@ const cloneDeep = require('lodash.clonedeep');
import * as path from 'path';
import * as cliInterface from '@snyk/cli-interface';
import chalk from 'chalk';
import { icon } from '../theme';
import * as debugModule from 'debug';

import { TestOptions, Options, MonitorOptions } from '../types';
Expand Down Expand Up @@ -86,7 +87,7 @@ export async function getMultiPluginResult(
});
debug(
chalk.bold.red(
`\n Failed to get dependencies for ${targetFile}\nERROR: ${err.message}\n`,
`\n${icon.ISSUE} Failed to get dependencies for ${targetFile}\nERROR: ${err.message}\n`,
),
);
}
Expand Down
9 changes: 6 additions & 3 deletions src/lib/plugins/sast/format/output-format.ts
@@ -1,6 +1,7 @@
import * as Sarif from 'sarif';
import * as Debug from 'debug';
import chalk from 'chalk';
import { icon, color } from '../../../theme';
import { colorTextBySeverity, SEVERITY } from '../../../snyk-test/common';
import { rightPadWithSpaces } from '../../../right-pad';
import { Options } from '../../../types';
Expand All @@ -26,7 +27,7 @@ export function getCodeDisplayedOutput(

const issuesText =
issues.low.join('') + issues.medium.join('') + issues.high.join('');
const summaryOKText = chalk.green('✔ Test completed');
const summaryOKText = color.status.success(`${icon.VALID} Test completed`);
const codeIssueSummary = getCodeIssuesSummary(issues);

return (
Expand Down Expand Up @@ -59,7 +60,9 @@ function getCodeIssuesSummary(issues: { [index: string]: string[] }): string {
} found`;
const issuesBySeverityText =
highSeverityText + mediumSeverityText + lowSeverityText;
const vulnPathsText = chalk.green('✔ Awesome! No issues were found.');
const vulnPathsText = color.status.success(
`${icon.VALID} Awesome! No issues were found.`,
);

return codeIssueCount > 0
? codeIssueFound + '\n' + issuesBySeverityText
Expand Down Expand Up @@ -89,7 +92,7 @@ function getIssues(
rulesMap[ruleId].shortDescription?.text || rulesMap[ruleId].name;
const ruleIdSeverityText = colorTextBySeverity(
severity,
` [${severity}] ${ruleName}`,
` ${icon.ISSUE} [${severity}] ${ruleName}`,
);
const artifactLocationUri = location.artifactLocation.uri;
const startLine = location.region.startLine;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/snyk-test/run-test.ts
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';
import * as pathUtil from 'path';
import * as debugModule from 'debug';
import chalk from 'chalk';
import { icon } from '../theme';
import { parsePackageString as moduleToObject } from 'snyk-module';
import * as depGraphLib from '@snyk/dep-graph';
import { IacScan } from './payload-schema';
Expand Down Expand Up @@ -573,7 +574,7 @@ async function assembleLocalPayloads(
if (!options.json && !options.quiet) {
console.warn(
chalk.bold.red(
` ${failedResults.length}/${failedResults.length +
`${icon.ISSUE} ${failedResults.length}/${failedResults.length +
deps.scannedProjects
.length} potential projects failed to get dependencies. Run with \`-d\` for debug output.`,
),
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/cli-test/cli-test.all-projects.spec.ts
Expand Up @@ -4,7 +4,7 @@ import * as depGraphLib from '@snyk/dep-graph';
import { CommandResult } from '../../../src/cli/commands/types';
import { AcceptanceTests } from './cli-test.acceptance.test';
import { getWorkspaceJSON } from '../workspace-helper';

import { icon } from '../../../src/lib/theme';
const simpleGradleGraph = depGraphLib.createFromJSON({
schemaVersion: '1.2.0',
pkgManager: {
Expand Down Expand Up @@ -91,7 +91,7 @@ export const AllProjectsTests: AcceptanceTests = {
);
t.same(
stdoutMessages,
'✗ 1/3 detected Gradle manifests did not return dependencies. ' +
`${icon.ISSUE} 1/3 detected Gradle manifests did not return dependencies. ` +
'They may have errored or were not included as part of a multi-project build. You may need to scan them individually with --file=path/to/file. Run with `-d` for more info.',
);
stubbedConsole.restore();
Expand Down
6 changes: 3 additions & 3 deletions test/acceptance/cli-test/cli-test.yarn-workspaces.spec.ts
Expand Up @@ -77,7 +77,7 @@ export const YarnWorkspacesTests: AcceptanceTests = {
});
t.match(
result.getDisplayResults(),
' Tested 1 dependencies for known vulnerabilities, no vulnerable paths found.',
' Tested 1 dependencies for known vulnerabilities, no vulnerable paths found.',
'correctly showing dep number',
);
t.match(result.getDisplayResults(), 'Package manager: yarn\n');
Expand Down Expand Up @@ -178,7 +178,7 @@ export const YarnWorkspacesTests: AcceptanceTests = {
});
t.match(
result.getDisplayResults(),
' Tested 1 dependencies for known vulnerabilities, no vulnerable paths found.',
' Tested 1 dependencies for known vulnerabilities, no vulnerable paths found.',
'correctly showing dep number',
);
t.match(result.getDisplayResults(), 'Package manager: yarn\n');
Expand Down Expand Up @@ -221,7 +221,7 @@ export const YarnWorkspacesTests: AcceptanceTests = {
});
t.match(
result.getDisplayResults(),
' Tested 1 dependencies for known vulnerabilities, no vulnerable paths found.',
' Tested 1 dependencies for known vulnerabilities, no vulnerable paths found.',
'correctly showing dep number',
);
t.match(result.getDisplayResults(), 'Package manager: yarn\n');
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/demo-os/core/test/unit/server_utils_spec.js
Expand Up @@ -15,7 +15,7 @@ describe('Safe String', function () {
});

it('should remove non ascii characters', function () {
var result = safeString('howtowin');
var result = safeString('howtowin');
result.should.equal('howtowin');
});

Expand Down
2 changes: 1 addition & 1 deletion test/system/remote-package.test.ts
Expand Up @@ -152,7 +152,7 @@ test('test for existing remote package with dev-deps only with --dev', async (t)
.pop();
t.deepEqual(
lastLine,
' Tested lodash@4.17.11 for known vulnerabilities, no vulnerable paths found.',
' Tested lodash@4.17.11 for known vulnerabilities, no vulnerable paths found.',
'successfully tested lodash@4.17.11',
);
} catch (error) {
Expand Down

0 comments on commit 3292ffb

Please sign in to comment.