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 {
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

@ -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) {

@ -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]] = ""
}
}
}

@ -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 {

@ -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
}
return matches[1], line, matches[4]
}

Loading…
Cancel
Save