From f30b7f44d504d27e472732ba84f9b30a75598238 Mon Sep 17 00:00:00 2001 From: Craig Furman Date: Thu, 29 Jul 2021 15:51:25 +0100 Subject: [PATCH] fix: more context in some IaC output 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. --- src/lib/formatters/iac-output.ts | 2 +- src/lib/formatters/remediation-based-format-issues.ts | 4 ++-- src/lib/formatters/test/display-result.ts | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib/formatters/iac-output.ts b/src/lib/formatters/iac-output.ts index 5ca8ce2ce1a..014b9751cd0 100644 --- a/src/lib/formatters/iac-output.ts +++ b/src/lib/formatters/iac-output.ts @@ -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}`; } diff --git a/src/lib/formatters/remediation-based-format-issues.ts b/src/lib/formatters/remediation-based-format-issues.ts index ba67191478b..e65a4861bdd 100644 --- a/src/lib/formatters/remediation-based-format-issues.ts +++ b/src/lib/formatters/remediation-based-format-issues.ts @@ -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( diff --git a/src/lib/formatters/test/display-result.ts b/src/lib/formatters/test/display-result.ts index d036860a2a6..b70a4d49d01 100644 --- a/src/lib/formatters/test/display-result.ts +++ b/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'; @@ -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'); @@ -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; }