From e970263f4c8edb5c523672382cf3c303b27c638b Mon Sep 17 00:00:00 2001 From: Massimiliano Giovagnoli Date: Mon, 17 Mar 2025 13:21:24 +0100 Subject: [PATCH] feat(pkg/lint): log rule errors with level matching severity Before this commit all rule errors were printed as info logs, leading to rule error and warnings being omitted even in case of a rule error leading to the whole lint command to fail. This commit disables also rule error wrapping by rule id, in order to log each error with specific log level depending on the rule severity. Signed-off-by: Massimiliano Giovagnoli --- pkg/lint/linter.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/lint/linter.go b/pkg/lint/linter.go index 7ce6d6f43..eb8fec6f9 100644 --- a/pkg/lint/linter.go +++ b/pkg/lint/linter.go @@ -111,16 +111,22 @@ func (l *Linter) Lint(ctx context.Context, minSeverity Severity) (Result, error) // Print prints the result to stdout. func (l *Linter) Print(ctx context.Context, result Result) { log := clog.FromContext(ctx) - foundAny := false + if !result.HasErrors() { + log.Infof("No linting issues found!") + return + } for _, res := range result { - if res.Errors.WrapErrors() != nil { - foundAny = true - log.Infof("Package: %s: %s", res.File, res.Errors.WrapErrors()) + for _, v := range res.Errors { + switch v.Rule.Severity.Value { + case SeverityErrorLevel: + log.Errorf("Package: %s: %s", res.File, v.Error) + case SeverityWarningLevel: + log.Warnf("Package: %s: %s", res.File, v.Error) + case SeverityInfoLevel: + log.Infof("Package: %s: %s", res.File, v.Error) + } } } - if !foundAny { - log.Infof("No linting issues found!") - } } // PrintRules prints the rules to stdout.