-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
28 changed files
with
498 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
package common | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/defenseunicorns/pkg/helpers/v2" | ||
"github.com/fatih/color" | ||
|
||
"github.com/zarf-dev/zarf/src/pkg/lint" | ||
"github.com/zarf-dev/zarf/src/pkg/message" | ||
) | ||
|
||
// PrintFindings prints the findings in the LintError as a table. | ||
func PrintFindings(lintErr *lint.LintError) { | ||
mapOfFindingsByPath := lint.GroupFindingsByPath(lintErr.Findings, lintErr.PackageName) | ||
for _, findings := range mapOfFindingsByPath { | ||
lintData := [][]string{} | ||
for _, finding := range findings { | ||
sevColor := color.FgWhite | ||
switch finding.Severity { | ||
case lint.SevErr: | ||
sevColor = color.FgRed | ||
case lint.SevWarn: | ||
sevColor = color.FgYellow | ||
} | ||
|
||
lintData = append(lintData, []string{ | ||
colorWrap(string(finding.Severity), sevColor), | ||
colorWrap(finding.YqPath, color.FgCyan), | ||
finding.ItemizedDescription(), | ||
}) | ||
} | ||
var packagePathFromUser string | ||
if helpers.IsOCIURL(findings[0].PackagePathOverride) { | ||
packagePathFromUser = findings[0].PackagePathOverride | ||
} else { | ||
packagePathFromUser = filepath.Join(lintErr.BaseDir, findings[0].PackagePathOverride) | ||
} | ||
message.Notef("Linting package %q at %s", findings[0].PackageNameOverride, packagePathFromUser) | ||
message.Table([]string{"Type", "Path", "Message"}, lintData) | ||
} | ||
} | ||
|
||
func colorWrap(str string, attr color.Attribute) string { | ||
if !message.ColorEnabled() || str == "" { | ||
return str | ||
} | ||
return fmt.Sprintf("\x1b[%dm%s\x1b[0m", attr, str) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.