diff --git a/cmd/helm/lint.go b/cmd/helm/lint.go index 75402f70c..b602c3d0f 100644 --- a/cmd/helm/lint.go +++ b/cmd/helm/lint.go @@ -58,7 +58,6 @@ func newLintCmd(out io.Writer) *cobra.Command { if len(args) > 0 { paths = args } - if kubeVersion != "" { parsedKubeVersion, err := chartutil.ParseKubeVersion(kubeVersion) if err != nil { @@ -66,7 +65,6 @@ func newLintCmd(out io.Writer) *cobra.Command { } client.KubeVersion = parsedKubeVersion } - if client.WithSubcharts { for _, p := range paths { filepath.Walk(filepath.Join(p, "charts"), func(path string, info os.FileInfo, _ error) error { @@ -81,19 +79,32 @@ func newLintCmd(out io.Writer) *cobra.Command { }) } } - client.Namespace = settings.Namespace() vals, err := valueOpts.MergeValues(getter.All(settings)) if err != nil { return err + print("this is the error\n") + } + var ignorePatterns map[string]string + if lintIgnoreFile == "" { + // Uncomment to debug: + // print("empty") + dir, err := os.Getwd() + if err != nil { + panic(err) + } + lintIgnoreFile = filepath.Join(dir, ".helmlintignore") } - - var ignorePatterns []string if lintIgnoreFile != "" { - ignorePatterns, err = rules.ParseIgnoreFile(lintIgnoreFile) + fmt.Printf("\nthis is the path: %s\n", lintIgnoreFile) + ignorePatterns, err := rules.ParseIgnoreFile(lintIgnoreFile) + // Uncomment to debug: + // fmt.Println("Patterns:", ignorePatterns) + // fmt.Println("Errors:", err) if err != nil { return fmt.Errorf("failed to parse .helmlintignore file: %v", err) } + fmt.Println("Ignore Patterns:", ignorePatterns) } var message strings.Builder diff --git a/pkg/lint/lint.go b/pkg/lint/lint.go index 53b45c5e6..5778388e7 100644 --- a/pkg/lint/lint.go +++ b/pkg/lint/lint.go @@ -17,6 +17,9 @@ limitations under the License. package lint import ( + "fmt" + "log" + "io/ioutil" "path/filepath" "helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/lint/rules" @@ -27,9 +30,16 @@ 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 []string + var ignorePatterns map[string]string + var err error if lintIgnoreFile != "" { - ignorePatterns, _ = rules.ParseIgnoreFile(lintIgnoreFile) // Simplified error handling for the example + ignorePatterns, err = rules.ParseIgnoreFile(lintIgnoreFile) + for key, value := range ignorePatterns { + fmt.Printf("Pattern: %s, Error: %s\n", key, value) + } + // Review this to properly handle logging + log.SetOutput(ioutil.Discard) + log.Println(err) } linter := support.Linter{ChartDir: chartDir} if rules.IsIgnored(chartDir, ignorePatterns) { diff --git a/pkg/lint/rules/ignore.go b/pkg/lint/rules/ignore.go index f563eb067..ec57f95ec 100644 --- a/pkg/lint/rules/ignore.go +++ b/pkg/lint/rules/ignore.go @@ -6,8 +6,8 @@ import ( "strings" ) -func ParseIgnoreFile(filePath string) ([]string, error) { - var patterns []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 @@ -17,8 +17,13 @@ func ParseIgnoreFile(filePath string) ([]string, error) { scanner := bufio.NewScanner(file) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) - if line != "" && !strings.HasPrefix(line, "#") { - patterns = append(patterns, line) + if line != "" && !strings.HasPrefix(line, "#") { + parts := strings.SplitN(line, " ", 2) + if len(parts) > 1 { + patterns[parts[0]] = parts[1] + } else if len(parts) == 1 { + patterns[parts[0]] = "" + } } } diff --git a/pkg/lint/rules/isignored.go b/pkg/lint/rules/isignored.go index 150521cec..dd7a3c273 100644 --- a/pkg/lint/rules/isignored.go +++ b/pkg/lint/rules/isignored.go @@ -6,8 +6,8 @@ import ( "fmt" ) -func IsIgnored(path string, patterns []string) bool { - for _, pattern := range patterns { +func IsIgnored(path string, patterns map[string]string) bool { + for pattern, _ := range patterns { cleanedPath := filepath.Clean(path) cleanedPattern := filepath.Clean(pattern) if match, err := filepath.Match(cleanedPattern, cleanedPath); err == nil && match { diff --git a/pkg/lint/rules/utils.go b/pkg/lint/rules/utils.go index 0353c2378..0f3f9f29d 100644 --- a/pkg/lint/rules/utils.go +++ b/pkg/lint/rules/utils.go @@ -5,14 +5,19 @@ import ( "strconv" ) -func parseErrorDetails(err string) (string, int, int) { - re := regexp.MustCompile(`([^:]+):(\d+):(\d+): executing`) +// parseErrorDetails extracts the file path and the line of the error from a given error message. +func parseErrorDetails(err string) (filePath string, line int, snippet string) { + // Regular expression to find the file path and line:column numbers + // This pattern assumes the error format is stable and always similar to the provided example + re := regexp.MustCompile(`(?m)([^:]+):(\d+):(\d+): executing "([^"]+)"`) matches := re.FindStringSubmatch(err) - if len(matches) < 4 { - return "", 0, 0 // Return default values if the format does not match + if len(matches) < 5 { + return "", 0, "" // Return default empty values if the format does not match + } + line, errConvert := strconv.Atoi(matches[2]) + if errConvert != nil { + return matches[1], 0, matches[4] } - line, _ := strconv.Atoi(matches[2]) - col, _ := strconv.Atoi(matches[3]) - return matches[1], line, col -} \ No newline at end of file + return matches[1], line, matches[4] +}