diff --git a/cmd/helm/lint.go b/cmd/helm/lint.go index b385e2148..2f3129b65 100644 --- a/cmd/helm/lint.go +++ b/cmd/helm/lint.go @@ -30,8 +30,8 @@ import ( "helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/cli/values" "helm.sh/helm/v3/pkg/getter" - "helm.sh/helm/v3/pkg/lint/support" "helm.sh/helm/v3/pkg/lint/rules" + "helm.sh/helm/v3/pkg/lint/support" ) var longLintHelp = ` @@ -48,7 +48,6 @@ func newLintCmd(out io.Writer) *cobra.Command { valueOpts := &values.Options{} var kubeVersion string var lintIgnoreFile string - var debug bool cmd := &cobra.Command{ Use: "lint PATH", @@ -87,16 +86,14 @@ func newLintCmd(out io.Writer) *cobra.Command { } var ignorePatterns map[string][]string if lintIgnoreFile != "" { - if debug { - fmt.Printf("\nUsing ignore file: %s\n", lintIgnoreFile) - } + debug("\nUsing ignore file: %s\n", lintIgnoreFile) ignorePatterns, err = rules.ParseIgnoreFile(lintIgnoreFile) } var message strings.Builder failed := 0 for _, path := range paths { result := client.Run([]string{path}, vals) - filteredResult := FilterIgnoredMessages(result, ignorePatterns, debug) + filteredResult := FilterIgnoredMessages(result, ignorePatterns, settings.Debug) fmt.Fprintf(&message, "==> Linting %s\n", path) for _, msg := range filteredResult.Messages { fmt.Fprintf(&message, "%s\n", msg) @@ -125,7 +122,6 @@ func newLintCmd(out io.Writer) *cobra.Command { f.BoolVar(&client.Quiet, "quiet", false, "print only warnings and errors") f.StringVar(&kubeVersion, "kube-version", "", "Kubernetes version used for capabilities and deprecation checks") f.StringVar(&lintIgnoreFile, "lint-ignore-file", "", "path to .helmlintignore file to specify ignore patterns") - f.BoolVar(&debug, "debug", false, "enable debug output") return cmd } @@ -171,3 +167,15 @@ func extractFullPathFromError(errorString string) string { } return "" } + +/* TODO HIP-0019 + - find ignore file path for a subchart + - add a chart or two for the end to end tests via testdata like in pkg/lint/lint_test.go + - review debug / output patterns across the helm project + + Later/never + - XDG support + - helm config file support + - ignore file validation + - +*/ \ No newline at end of file diff --git a/pkg/ignore/README.md b/pkg/ignore/README.md new file mode 100644 index 000000000..ed66d8517 --- /dev/null +++ b/pkg/ignore/README.md @@ -0,0 +1,52 @@ +## HIP-0019 helm lint ignore file + +### manual test + +```bash +go run ./cmd/helm lint ~/repositories/gitlab/chart/ --lint-ignore-file ~/repositories/gitlab/chart/.helmlintignore --with-subcharts --debug +``` + +``` +go run ./cmd/helm lint ../gitlab/chart/ --lint-ignore-file ../gitlab/chart/.helmlintignore --with-subcharts --debug +``` + +### code flow diagram + +```mermaid +flowchart LR + classDef lintIgnores fill:#f9f,stroke:#333,stroke-width:4px; + +subgraph main["package main"] + Filter:::lintIgnores + + root --> cmdHelmLint + cmdHelmLint[cmd/helm/lint.go] --> action + cmdHelmLint[cmd/helm/lint.go] --> lint/rules + cmdHelmLint[cmd/helm/lint.go] --> lint/support + cmdHelmLint --> Filter["FilterIgnoredMessages()"] + cmdHelmLint --> action +end + +subgraph action["package action"] + action --> aNewLint["action.NewLint()"] + action --> typeLint["type action.Lint"] + action --> typeLintResult["type action.LintResult"] +end + +subgraph lint["package lint"] + subgraph support["package lint/support"] + lint/support + lint/support --> Message["type support.Message"] + end + + subgraph rules + parseIgnore:::lintIgnores + lint/rules + lint/rules --> parseIgnore["rules.ParseIgnoreFile()"] + end + +end + + + +``` \ No newline at end of file diff --git a/pkg/lint/rules/ignore.go b/pkg/lint/rules/ignore.go index 8e6b24d9d..70c1126e3 100644 --- a/pkg/lint/rules/ignore.go +++ b/pkg/lint/rules/ignore.go @@ -2,7 +2,9 @@ package rules import ( "bufio" + "fmt" "os" + "path/filepath" "strings" ) @@ -31,3 +33,19 @@ func ParseIgnoreFile(filePath string) (map[string][]string, error) { return patterns, scanner.Err() } + +func IsIgnored(errorMessage string, patterns map[string][]string) bool { + for path, pathPatterns := range patterns { + cleanedPath := filepath.Clean(path) + 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/rules/isignored.go b/pkg/lint/rules/isignored.go deleted file mode 100644 index 481df142b..000000000 --- a/pkg/lint/rules/isignored.go +++ /dev/null @@ -1,27 +0,0 @@ -package rules - -import ( - "path/filepath" - "strings" - "fmt" -) - -type LintResult struct { - Messages []string -} - -func IsIgnored(errorMessage string, patterns map[string][]string) bool { - for path, pathPatterns := range patterns { - cleanedPath := filepath.Clean(path) - 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 -} -