Skip to content

Commit

Permalink
fix: more context in some IaC output
Browse files Browse the repository at this point in the history
Display the entire resource path (instead of slicing off the first
element) and the entire target file relative path (instead of just the
basename) in "regular" (not json or sarif) IaC test output.

This allows users to form unambiguous paths (including file) to use in
`.snyk` ignore rules.
  • Loading branch information
Craig Furman committed Aug 6, 2021
1 parent c9f28eb commit f30b7f4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib/formatters/iac-output.ts
Expand Up @@ -30,7 +30,7 @@ function formatIacIssue(
let introducedBy = '';
if (path) {
// In this mode, we show only one path by default, for compactness
const pathStr = printPath(path);
const pathStr = printPath(path, 0);
introducedBy = `\n introduced by ${pathStr}`;
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/formatters/remediation-based-format-issues.ts
Expand Up @@ -417,8 +417,8 @@ function constructUnfixableText(
return unfixableIssuesTextArray;
}

export function printPath(path: string[]) {
return path.slice(1).join(PATH_SEPARATOR);
export function printPath(path: string[], slice = 1) {
return path.slice(slice).join(PATH_SEPARATOR);
}

export function formatIssue(
Expand Down
5 changes: 2 additions & 3 deletions src/lib/formatters/test/display-result.ts
@@ -1,4 +1,3 @@
import * as pathLib from 'path';
import chalk from 'chalk';
import { icon, color } from '../../theme';
import { isCI } from '../../../lib/is-ci';
Expand Down Expand Up @@ -39,7 +38,7 @@ export function displayResult(
const localPackageTest = isLocalFolder(options.path);
let testingPath = options.path;
if (options.iac && res.targetFile) {
testingPath = pathLib.basename(res.targetFile);
testingPath = res.targetFile;
}
const prefix = chalk.bold.white('\nTesting ' + testingPath + '...\n\n');

Expand All @@ -57,7 +56,7 @@ export function displayResult(
if (res.dependencyCount) {
pathOrDepsText += res.dependencyCount + ' dependencies';
} else if (options.iac && res.targetFile) {
pathOrDepsText += pathLib.basename(res.targetFile);
pathOrDepsText += res.targetFile;
} else {
pathOrDepsText += options.path;
}
Expand Down

0 comments on commit f30b7f4

Please sign in to comment.