parsing fix

Signed-off-by: Danilo Patrucco <danilo.patrucco@gmail.com>
pull/13205/head
Danilo Patrucco 1 year ago
parent 0d5e5b34f1
commit 00809584d4

@ -58,7 +58,6 @@ func newLintCmd(out io.Writer) *cobra.Command {
if len(args) > 0 { if len(args) > 0 {
paths = args paths = args
} }
if kubeVersion != "" { if kubeVersion != "" {
parsedKubeVersion, err := chartutil.ParseKubeVersion(kubeVersion) parsedKubeVersion, err := chartutil.ParseKubeVersion(kubeVersion)
if err != nil { if err != nil {
@ -66,7 +65,6 @@ func newLintCmd(out io.Writer) *cobra.Command {
} }
client.KubeVersion = parsedKubeVersion client.KubeVersion = parsedKubeVersion
} }
if client.WithSubcharts { if client.WithSubcharts {
for _, p := range paths { for _, p := range paths {
filepath.Walk(filepath.Join(p, "charts"), func(path string, info os.FileInfo, _ error) error { 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() client.Namespace = settings.Namespace()
vals, err := valueOpts.MergeValues(getter.All(settings)) vals, err := valueOpts.MergeValues(getter.All(settings))
if err != nil { if err != nil {
return err 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 != "" { 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 { if err != nil {
return fmt.Errorf("failed to parse .helmlintignore file: %v", err) return fmt.Errorf("failed to parse .helmlintignore file: %v", err)
} }
fmt.Println("Ignore Patterns:", ignorePatterns)
} }
var message strings.Builder var message strings.Builder

@ -17,6 +17,9 @@ limitations under the License.
package lint package lint
import ( import (
"fmt"
"log"
"io/ioutil"
"path/filepath" "path/filepath"
"helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/lint/rules" "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 { func AllWithKubeVersion(basedir string, values map[string]interface{}, namespace string, kubeVersion *chartutil.KubeVersion, lintIgnoreFile string) support.Linter {
chartDir, _ := filepath.Abs(basedir) chartDir, _ := filepath.Abs(basedir)
var ignorePatterns []string var ignorePatterns map[string]string
var err error
if lintIgnoreFile != "" { 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} linter := support.Linter{ChartDir: chartDir}
if rules.IsIgnored(chartDir, ignorePatterns) { if rules.IsIgnored(chartDir, ignorePatterns) {

@ -6,8 +6,8 @@ import (
"strings" "strings"
) )
func ParseIgnoreFile(filePath string) ([]string, error) { func ParseIgnoreFile(filePath string) (map[string]string, error) {
var patterns []string patterns := make(map[string]string)
file, err := os.Open(filePath) file, err := os.Open(filePath)
if err != nil { if err != nil {
return nil, err return nil, err
@ -17,8 +17,13 @@ func ParseIgnoreFile(filePath string) ([]string, error) {
scanner := bufio.NewScanner(file) scanner := bufio.NewScanner(file)
for scanner.Scan() { for scanner.Scan() {
line := strings.TrimSpace(scanner.Text()) line := strings.TrimSpace(scanner.Text())
if line != "" && !strings.HasPrefix(line, "#") { if line != "" && !strings.HasPrefix(line, "#") {
patterns = append(patterns, line) parts := strings.SplitN(line, " ", 2)
if len(parts) > 1 {
patterns[parts[0]] = parts[1]
} else if len(parts) == 1 {
patterns[parts[0]] = ""
}
} }
} }

@ -6,8 +6,8 @@ import (
"fmt" "fmt"
) )
func IsIgnored(path string, patterns []string) bool { func IsIgnored(path string, patterns map[string]string) bool {
for _, pattern := range patterns { for pattern, _ := range patterns {
cleanedPath := filepath.Clean(path) cleanedPath := filepath.Clean(path)
cleanedPattern := filepath.Clean(pattern) cleanedPattern := filepath.Clean(pattern)
if match, err := filepath.Match(cleanedPattern, cleanedPath); err == nil && match { if match, err := filepath.Match(cleanedPattern, cleanedPath); err == nil && match {

@ -5,14 +5,19 @@ import (
"strconv" "strconv"
) )
func parseErrorDetails(err string) (string, int, int) { // parseErrorDetails extracts the file path and the line of the error from a given error message.
re := regexp.MustCompile(`([^:]+):(\d+):(\d+): executing`) 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) matches := re.FindStringSubmatch(err)
if len(matches) < 4 { if len(matches) < 5 {
return "", 0, 0 // Return default values if the format does not match 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]) return matches[1], line, matches[4]
col, _ := strconv.Atoi(matches[3]) }
return matches[1], line, col
}

Loading…
Cancel
Save