Skip to content

Commit

Permalink
chore: apply prettier changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thisislawatts committed Sep 4, 2024
1 parent d8af1c7 commit efc6bee
Show file tree
Hide file tree
Showing 139 changed files with 5,062 additions and 5,425 deletions.
3 changes: 2 additions & 1 deletion dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const fs = require('fs');
const MAX_COMMIT_MESSAGE_LENGTH = 72;

function checkCommitMessage(commitMessage, url) {
const firstLineRegex = /^Merge.*|(feat|fix|chore|test|docs|refactor|revert)(\([a-z0-9-_]+\))?:(.+)$/;
const firstLineRegex =
/^Merge.*|(feat|fix|chore|test|docs|refactor|revert)(\([a-z0-9-_]+\))?:(.+)$/;
if (!firstLineRegex.test(commitMessage)) {
fail(
`"[${commitMessage}](${url})" is not using a valid commit message format. For commit guidelines, see: [CONTRIBUTING](https://github.com/snyk/snyk/blob/main/CONTRIBUTING.md#creating-commits).`,
Expand Down
3 changes: 1 addition & 2 deletions packages/iac-cli-alert/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ async function discoverConsecutiveFailures(
async function sendSlackAlert() {
console.log('IaC smoke tests failed. Sending Slack alert...');
const args: IncomingWebhookDefaultArguments = {
text:
'Infrastructure as Code Smoke Tests jobs failed. \n Core functionality in the IaC+ CLI flows may not be working as expected. \n <https://github.com/snyk/cli/actions/workflows/iac-smoke-tests.yml?query=workflow%3A|Infrastructure as Code Smoke Tests Results> \n <https://www.notion.so/snyk/Alert-Infrastructure-as-Code-Smoke-Tests-jobs-failed-ad6a89ea7fb74cc4aab4763c5ac59cbc|View the runbook for this alert>',
text: 'Infrastructure as Code Smoke Tests jobs failed. \n Core functionality in the IaC+ CLI flows may not be working as expected. \n <https://github.com/snyk/cli/actions/workflows/iac-smoke-tests.yml?query=workflow%3A|Infrastructure as Code Smoke Tests Results> \n <https://www.notion.so/snyk/Alert-Infrastructure-as-Code-Smoke-Tests-jobs-failed-ad6a89ea7fb74cc4aab4763c5ac59cbc|View the runbook for this alert>',
};
await slackWebhook.send(args);
console.log('Slack alert sent.');
Expand Down
10 changes: 3 additions & 7 deletions packages/snyk-fix/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ export async function fix(
const spinner = ora({ isSilent: options.quiet, stream: process.stdout });

let resultsByPlugin: FixHandlerResultByPlugin = {};
const {
vulnerable,
notVulnerable: nothingToFix,
} = await partitionByVulnerable(entities);
const { vulnerable, notVulnerable: nothingToFix } =
await partitionByVulnerable(entities);
const entitiesPerType = groupEntitiesPerScanType(vulnerable);
const exceptions: ErrorsByEcoSystem = {};
await pMap(
Expand Down Expand Up @@ -94,9 +92,7 @@ export async function fix(
};
}

export function groupEntitiesPerScanType(
entities: EntityToFix[],
): {
export function groupEntitiesPerScanType(entities: EntityToFix[]): {
[type: string]: EntityToFix[];
} {
const entitiesPerType: {
Expand Down
4 changes: 1 addition & 3 deletions packages/snyk-fix/src/lib/issues/fixable-issues.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { DependencyPins, DependencyUpdates, TestResult } from '../../types';

export function hasFixableIssues(
results: TestResult[],
): {
export function hasFixableIssues(results: TestResult[]): {
hasFixes: boolean;
count: number;
} {
Expand Down
9 changes: 6 additions & 3 deletions packages/snyk-fix/src/lib/issues/issues-by-severity.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { IssuesData } from '../../types';

export function getIssueCountBySeverity(
issueData: IssuesData[],
): { low: string[]; medium: string[]; high: string[]; critical: string[] } {
export function getIssueCountBySeverity(issueData: IssuesData[]): {
low: string[];
medium: string[];
high: string[];
critical: string[];
} {
const total = {
low: [],
medium: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,12 @@ export async function showResultsSummary(
options: FixOptions,
total: number,
): Promise<string> {
const successfulFixesSummary = generateSuccessfulFixesSummary(
resultsByPlugin,
);
const {
summary: unresolvedSummary,
count: unresolvedCount,
} = generateUnresolvedSummary(resultsByPlugin, exceptions);
const {
summary: overallSummary,
count: changedCount,
} = generateOverallSummary(
resultsByPlugin,
exceptions,
nothingToFix,
options,
);
const successfulFixesSummary =
generateSuccessfulFixesSummary(resultsByPlugin);
const { summary: unresolvedSummary, count: unresolvedCount } =
generateUnresolvedSummary(resultsByPlugin, exceptions);
const { summary: overallSummary, count: changedCount } =
generateOverallSummary(resultsByPlugin, exceptions, nothingToFix, options);

const getHelpText = `${reTryMessage}. ${contactSupportMessage}`;

Expand Down
7 changes: 4 additions & 3 deletions packages/snyk-fix/src/partition-by-vulnerable.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { EntityToFix } from './types';

export function partitionByVulnerable(
entities: EntityToFix[],
): { vulnerable: EntityToFix[]; notVulnerable: EntityToFix[] } {
export function partitionByVulnerable(entities: EntityToFix[]): {
vulnerable: EntityToFix[];
notVulnerable: EntityToFix[];
} {
const vulnerable: EntityToFix[] = [];
const notVulnerable: EntityToFix[] = [];

Expand Down
5 changes: 2 additions & 3 deletions packages/snyk-fix/src/plugins/package-tool-supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ export async function checkPackageToolSupported(
return;
}

const { supported, versions } = supportFunc[
packageManager
].isSupportedVersion(version);
const { supported, versions } =
supportFunc[packageManager].isSupportedVersion(version);
if (!supported) {
const spinnerMessage = ` ${version} ${packageManager} version detected. Currently the following ${packageManager} versions are supported: ${versions.join(
',',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ export async function isSupported(
return { supported: true };
}

export async function partitionByFixable(
entities: EntityToFix[],
): Promise<{
export async function partitionByFixable(entities: EntityToFix[]): Promise<{
skipped: Array<WithUserMessage<EntityToFix>>;
fixable: EntityToFix[];
}> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ export async function extractProvenance(
...provenance,
[relativeTargetFileName]: parseRequirementsFile(requirementsTxt),
};
const { containsRequire, matches } = await containsRequireDirective(
requirementsTxt,
);
const { containsRequire, matches } =
await containsRequireDirective(requirementsTxt);
if (containsRequire) {
for (const match of matches) {
const requiredFilePath = match[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ function filterOutAppliedUpgrades(
return pinRemediation;
}

function sortByDirectory(
entities: EntityToFix[],
): {
function sortByDirectory(entities: EntityToFix[]): {
[dir: string]: Array<{
entity: EntityToFix;
dir: string;
Expand All @@ -274,9 +272,7 @@ function sortByDirectory(
return groupBy(sorted, 'dir');
}

export async function selectFileForPinning(
entity: EntityToFix,
): Promise<{
export async function selectFileForPinning(entity: EntityToFix): Promise<{
fileName: string;
fileContent: string;
}> {
Expand All @@ -287,9 +283,8 @@ export async function selectFileForPinning(
let fileName = base;
let requirementsTxt = await workspace.readFile(targetFile);

const { containsRequire, matches } = await containsRequireDirective(
requirementsTxt,
);
const { containsRequire, matches } =
await containsRequireDirective(requirementsTxt);
const constraintsMatch = matches.filter((m) => m.includes('c'));
if (containsRequire && constraintsMatch[0]) {
// prefer to pin in constraints file if present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ export function generatePins(
const pinnedRequirements = Object.keys(standardizedPins)
.map((pkgNameAtVersion) => {
const [pkgName, version] = pkgNameAtVersion.split('@');
const newVersion = standardizedPins[pkgNameAtVersion].upgradeTo.split(
'@',
)[1];
const newVersion =
standardizedPins[pkgNameAtVersion].upgradeTo.split('@')[1];
const newRequirement = `${standardizePackageName(
pkgName,
)}>=${newVersion}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ export function updateDependencies(
updatedManifest: string;
changes: FixChangesSummary[];
} {
const {
requirements,
endsWithNewLine: shouldEndWithNewLine,
} = parsedRequirementsData;
const { requirements, endsWithNewLine: shouldEndWithNewLine } =
parsedRequirementsData;
if (!requirements.length) {
debug(
'Error: Expected to receive parsed manifest data. Is manifest empty?',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function extractDependencyDataFromLine(

// Regex to match against a Python package specifier. Any invalid lines (or
// lines we can't handle) should have been returned this point.
const regex = /([A-Z0-9-._]*)(!=|===|==|>=|<=|>|<|~=)(\d*\.?\d*\.?\d*[A-Z0-9]*)(.*)/i;
const regex =
/([A-Z0-9-._]*)(!=|===|==|>=|<=|>|<|~=)(\d*\.?\d*\.?\d*[A-Z0-9]*)(.*)/i;
const result = regex.exec(requirementText);
if (result !== null) {
requirement.name = standardizePackageName(result[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ export async function pipenvAdd(
const targetFilePath = pathLib.resolve(entity.workspace.path, targetFile);
const { dir } = pathLib.parse(targetFilePath);
if (!options.dryRun && upgrades.length) {
const {
stderr,
stdout,
command,
exitCode,
} = await pipenvPipfileFix.pipenvInstall(dir, upgrades, {
python: entity.options.command,
});
const { stderr, stdout, command, exitCode } =
await pipenvPipfileFix.pipenvInstall(dir, upgrades, {
python: entity.options.command,
});
debug('`pipenv add` returned:', { stderr, stdout, command });
if (exitCode !== 0) {
pipenvCommand = command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { MissingFileNameError } from '../../../lib/errors/missing-file-name';
import { NoFixesCouldBeAppliedError } from '../../../lib/errors/no-fixes-applied';
import { EntityToFix, RemediationChanges, Workspace } from '../../../types';

export function validateRequiredData(
entity: EntityToFix,
): {
export function validateRequiredData(entity: EntityToFix): {
remediation: RemediationChanges;
targetFile: string;
workspace: Workspace;
Expand Down
10 changes: 4 additions & 6 deletions packages/snyk-fix/src/plugins/python/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ export async function pythonFix(
},
};
const results = handlerResult.python;
const { entitiesPerType, skipped: notSupported } = mapEntitiesPerHandlerType(
entities,
);
const { entitiesPerType, skipped: notSupported } =
mapEntitiesPerHandlerType(entities);
results.skipped.push(...notSupported);

spinner.stopAndPersist({
Expand All @@ -57,9 +56,8 @@ export async function pythonFix(
const handler = loadHandler(projectType as SUPPORTED_HANDLER_TYPES);
// drop unsupported Python entities early so only potentially fixable items get
// attempted to be fixed
const { fixable, skipped: notFixable } = await partitionByFixable(
projectsToFix,
);
const { fixable, skipped: notFixable } =
await partitionByFixable(projectsToFix);
results.skipped.push(...notFixable);

const { failed, skipped, succeeded } = await handler(fixable, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { SUPPORTED_HANDLER_TYPES } from './supported-handler-types';

const debug = debugLib('snyk-fix:python');

export function mapEntitiesPerHandlerType(
entities: EntityToFix[],
): {
export function mapEntitiesPerHandlerType(entities: EntityToFix[]): {
skipped: Array<WithUserMessage<EntityToFix>>;
entitiesPerType: {
[projectType in SUPPORTED_HANDLER_TYPES]: EntityToFix[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ describe('fix Pipfile Python projects', () => {
issueIds: ['vuln-id'],
reason: 'Locking failed',
success: false,
tip:
'Try running `pipenv install django==2.0.1 transitive==1.1.1`',
tip: 'Try running `pipenv install django==2.0.1 transitive==1.1.1`',
to: '[email protected]',
userMessage: 'Failed to upgrade django from 1.6.1 to 2.0.1',
},
Expand All @@ -174,8 +173,7 @@ describe('fix Pipfile Python projects', () => {
issueIds: [],
reason: 'Locking failed',
success: false,
tip:
'Try running `pipenv install django==2.0.1 transitive==1.1.1`',
tip: 'Try running `pipenv install django==2.0.1 transitive==1.1.1`',
to: '[email protected]',
userMessage: 'Failed to pin transitive from 1.0.0 to 1.1.1',
},
Expand Down Expand Up @@ -263,8 +261,7 @@ describe('fix Pipfile Python projects', () => {
success: false,
reason: err,
userMessage: 'Failed to upgrade django from 1.6.1 to 2.0.1',
tip:
'Try running `pipenv install django==2.0.1 transitive==1.1.1`',
tip: 'Try running `pipenv install django==2.0.1 transitive==1.1.1`',
issueIds: ['vuln-id'],
from: '[email protected]',
to: '[email protected]',
Expand All @@ -273,8 +270,7 @@ describe('fix Pipfile Python projects', () => {
success: false,
reason: err,
userMessage: 'Failed to pin transitive from 1.0.0 to 1.1.1',
tip:
'Try running `pipenv install django==2.0.1 transitive==1.1.1`',
tip: 'Try running `pipenv install django==2.0.1 transitive==1.1.1`',
issueIds: [],
from: '[email protected]',
to: '[email protected]',
Expand Down Expand Up @@ -716,8 +712,7 @@ describe('fix Pipfile Python projects (fix sequentially)', () => {
issueIds: ['vuln-id'],
reason: err,
success: false,
tip:
'Try running `pipenv install django==2.0.1 transitive==1.1.1`',
tip: 'Try running `pipenv install django==2.0.1 transitive==1.1.1`',
to: '[email protected]',
userMessage: 'Failed to upgrade django from 1.6.1 to 2.0.1',
},
Expand All @@ -726,8 +721,7 @@ describe('fix Pipfile Python projects (fix sequentially)', () => {
issueIds: [],
reason: err,
success: false,
tip:
'Try running `pipenv install django==2.0.1 transitive==1.1.1`',
tip: 'Try running `pipenv install django==2.0.1 transitive==1.1.1`',
to: '[email protected]',
userMessage: 'Failed to pin transitive from 1.0.0 to 1.1.1',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ describe('fix Poetry Python projects', () => {
issueIds: ['VULN-six'],
reason: err,
success: false,
tip:
'Try running `poetry install six==2.0.1 transitive==1.1.1`',
tip: 'Try running `poetry install six==2.0.1 transitive==1.1.1`',
to: '[email protected]',
userMessage: 'Failed to upgrade six from 1.1.6 to 2.0.1',
},
Expand All @@ -180,8 +179,7 @@ describe('fix Poetry Python projects', () => {
issueIds: [],
reason: err,
success: false,
tip:
'Try running `poetry install six==2.0.1 transitive==1.1.1`',
tip: 'Try running `poetry install six==2.0.1 transitive==1.1.1`',
to: '[email protected]',
userMessage: 'Failed to pin transitive from 1.0.0 to 1.1.1',
},
Expand Down
4 changes: 2 additions & 2 deletions packages/snyk-fix/test/helpers/generate-entity-to-fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function generateEntityToFix(
: {
issues: [],
issuesData: {},
depGraphData: ('' as unknown) as DepGraphData,
depGraphData: '' as unknown as DepGraphData,
};
const workspace = generateWorkspace(contents, path);
const cliTestOptions = {
Expand Down Expand Up @@ -112,7 +112,7 @@ export function generateTestResult(): TestResult {
title: 'Fake vuln',
},
},
depGraphData: ('' as unknown) as DepGraphData,
depGraphData: '' as unknown as DepGraphData,
remediation: {
unresolved: [],
upgrade: {},
Expand Down
Loading

0 comments on commit efc6bee

Please sign in to comment.