Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
juev committed Sep 10, 2024
1 parent 1bbbc43 commit 1b93b57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions pkg/errors/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package errors

import (
"errors"
"fmt"
"slices"
"strings"
Expand Down Expand Up @@ -39,20 +40,27 @@ type LintRuleErrorsList struct {
data []LintRuleError
}

// Add adds new error to the list if it doesn't exist yet.
// It first checks if error is empty (i.e. all its fields are empty strings)
// and then checks if error with the same ID, ObjectId and Text already exists in the list.
func (l *LintRuleErrorsList) Add(e LintRuleError) {
if e.IsEmpty() {
return
}
if slices.ContainsFunc(l.data, func(el LintRuleError) bool { return e.EqualsTo(el) }) {
if slices.ContainsFunc(l.data, e.EqualsTo) {
return
}
l.data = append(l.data, e)
}

// Merge merges another LintRuleErrorsList into current one, removing all duplicate errors.
func (l *LintRuleErrorsList) Merge(e LintRuleErrorsList) {
l.data = append(l.data, e.data...)
}

// ConvertToError converts LintRuleErrorsList to a single error.
// It returns an error that contains all errors from the list with a nice formatting.
// If the list is empty, it returns nil.
func (l *LintRuleErrorsList) ConvertToError() error {
if len(l.data) == 0 {
return nil
Expand All @@ -73,5 +81,5 @@ func (l *LintRuleErrorsList) ConvertToError() error {
}
builder.WriteString("\n")
}
return fmt.Errorf(builder.String())
return errors.New(builder.String())
}
4 changes: 2 additions & 2 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const (
)

type Manager struct {
Modules []*Module
Modules ModuleList
}

func NewManager() *Manager {
return &Manager{}
}

func (m Manager) LoadModules(dirs []string) []*Module {
func (m Manager) LoadModules(dirs []string) ModuleList {
var paths []string

for i := range dirs {
Expand Down
2 changes: 2 additions & 0 deletions pkg/manager/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type Module struct {
Chart *chart.Chart
}

type ModuleList []*Module

func (m *Module) String() string {
return fmt.Sprintf("{Name: %s, Namespace: %s, Path: %s}", m.Name, m.Namespace, m.Path)
}
Expand Down

0 comments on commit 1b93b57

Please sign in to comment.