Skip to content

Commit

Permalink
print out the number of warnings after completing a rule check
Browse files Browse the repository at this point in the history
Signed-off-by: Talon Bowler <talon.bowler@docker.com>
  • Loading branch information
daghack committed Aug 12, 2024
1 parent 38a8261 commit 182a898
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,17 +891,29 @@ func printResult(w io.Writer, f *controllerapi.PrintFunc, res map[string]string)
case "subrequests.describe":
return 0, printValue(w, subrequests.PrintDescribe, subrequests.SubrequestsDescribeDefinition.Version, f.Format, res)
case "lint":
err := printValue(w, lint.PrintLintViolations, lint.SubrequestLintDefinition.Version, f.Format, res)
if err != nil {
return 0, err
}

lintResults := lint.LintResults{}
if result, ok := res["result.json"]; ok {
if err := json.Unmarshal([]byte(result), &lintResults); err != nil {
return 0, err
}
}

if f.Format != "json" {
var warningCountMsg string
warningCount := len(lintResults.Warnings)
if warningCount == 1 {
warningCountMsg = "1 warning has been found!"
} else if warningCount > 1 {
warningCountMsg = fmt.Sprintf("%d warnings have been found!", warningCount)
}
fmt.Fprintf(w, "Check completed, %s\n", warningCountMsg)
}

err := printValue(w, lint.PrintLintViolations, lint.SubrequestLintDefinition.Version, f.Format, res)
if err != nil {
return 0, err
}

if lintResults.Error != nil {
// Print the error message and the source
// Normally, we would use `errdefs.WithSource` to attach the source to the
Expand Down

0 comments on commit 182a898

Please sign in to comment.