diff --git a/cmd/helm/lint.go b/cmd/helm/lint.go index b602c3d0f..94612fc45 100644 --- a/cmd/helm/lint.go +++ b/cmd/helm/lint.go @@ -85,7 +85,7 @@ func newLintCmd(out io.Writer) *cobra.Command { return err print("this is the error\n") } - var ignorePatterns map[string]string + var ignorePatterns map[string][]string if lintIgnoreFile == "" { // Uncomment to debug: // print("empty") @@ -112,19 +112,17 @@ func newLintCmd(out io.Writer) *cobra.Command { errorsOrWarnings := 0 for _, path := range paths { - if rules.IsIgnored(path, ignorePatterns) { - continue - } result := client.Run([]string{path}, vals) - - hasWarningsOrErrors := action.HasWarningsOrErrors(result) + filteredResult := FilterIgnoredMessages(result, ignorePatterns) + hasWarningsOrErrors := len(filteredResult.Messages) > 0 if hasWarningsOrErrors { errorsOrWarnings++ } if client.Quiet && !hasWarningsOrErrors { continue } + fmt.Fprintf(&message, "==> Linting %s\n", path) @@ -171,3 +169,31 @@ func newLintCmd(out io.Writer) *cobra.Command { return cmd } +// Need to figure out how to pull this function out of here + +func FilterIgnoredMessages(result *action.LintResult, patterns map[string][]string) *action.LintResult { + filteredMessages := make([]support.Message, 0) + for _, msg := range result.Messages { + ignore := false + for path, pathPatterns := range patterns { + cleanedPath := filepath.Clean(path) + if strings.Contains(msg.Path, cleanedPath) { // Check if the message path matches the ignored path + for _, pattern := range pathPatterns { + if strings.Contains(msg.Err.Error(), pattern) { // Assuming we are matching patterns against the error message + fmt.Printf("Ignoring message: [%s] %s\n", msg.Path, msg.Err.Error()) + ignore = true + break + } + } + } + if ignore { + break + } + } + if !ignore { + filteredMessages = append(filteredMessages, msg) + } + } + return &action.LintResult{Messages: filteredMessages} +} + diff --git a/pkg/lint/lint.go b/pkg/lint/lint.go index 5778388e7..178079839 100644 --- a/pkg/lint/lint.go +++ b/pkg/lint/lint.go @@ -30,7 +30,7 @@ func All(basedir string, values map[string]interface{}, namespace string, _ bool } func AllWithKubeVersion(basedir string, values map[string]interface{}, namespace string, kubeVersion *chartutil.KubeVersion, lintIgnoreFile string) support.Linter { chartDir, _ := filepath.Abs(basedir) - var ignorePatterns map[string]string + var ignorePatterns map[string][]string var err error if lintIgnoreFile != "" { ignorePatterns, err = rules.ParseIgnoreFile(lintIgnoreFile) diff --git a/pkg/lint/rules/ignore.go b/pkg/lint/rules/ignore.go index ec57f95ec..848368920 100644 --- a/pkg/lint/rules/ignore.go +++ b/pkg/lint/rules/ignore.go @@ -6,8 +6,8 @@ import ( "strings" ) -func ParseIgnoreFile(filePath string) (map[string]string, error) { - patterns := make(map[string]string) +func ParseIgnoreFile(filePath string) (map[string][]string, error) { + patterns := make(map[string][]string) file, err := os.Open(filePath) if err != nil { return nil, err @@ -20,12 +20,14 @@ func ParseIgnoreFile(filePath string) (map[string]string, error) { if line != "" && !strings.HasPrefix(line, "#") { parts := strings.SplitN(line, " ", 2) if len(parts) > 1 { - patterns[parts[0]] = parts[1] + // Check if the key already exists and append to its slice + patterns[parts[0]] = append(patterns[parts[0]], parts[1]) } else if len(parts) == 1 { - patterns[parts[0]] = "" + // Add an empty pattern if only the path is present + patterns[parts[0]] = append(patterns[parts[0]], "") } } } return patterns, scanner.Err() -} \ No newline at end of file +} diff --git a/pkg/lint/rules/isignored.go b/pkg/lint/rules/isignored.go index dd7a3c273..481df142b 100644 --- a/pkg/lint/rules/isignored.go +++ b/pkg/lint/rules/isignored.go @@ -6,20 +6,22 @@ import ( "fmt" ) -func IsIgnored(path string, patterns map[string]string) bool { - for pattern, _ := range patterns { +type LintResult struct { + Messages []string +} + +func IsIgnored(errorMessage string, patterns map[string][]string) bool { + for path, pathPatterns := range patterns { cleanedPath := filepath.Clean(path) - cleanedPattern := filepath.Clean(pattern) - if match, err := filepath.Match(cleanedPattern, cleanedPath); err == nil && match { - fmt.Printf("Ignoring path: %s due to pattern: %s\n", path, pattern) - return true - } - if strings.HasSuffix(cleanedPattern, "/") || strings.HasSuffix(cleanedPattern, "\\") { - patternDir := strings.TrimRight(cleanedPattern, "/\\") - if strings.HasPrefix(cleanedPath, patternDir) { - return true + if strings.Contains(errorMessage, cleanedPath) { + for _, pattern := range pathPatterns { + if strings.Contains(errorMessage, pattern) { + fmt.Printf("Ignoring error related to path: %s with pattern: %s\n", path, pattern) + return true + } } } } return false } + diff --git a/pkg/lint/support/message.go b/pkg/lint/support/message.go index 5efbc7a61..161504d9e 100644 --- a/pkg/lint/support/message.go +++ b/pkg/lint/support/message.go @@ -33,6 +33,7 @@ const ( // sev matches the *Sev states. var sev = []string{"UNKNOWN", "INFO", "WARNING", "ERROR"} + // Linter encapsulates a linting run of a particular chart. type Linter struct { Messages []Message