mirror of https://github.com/helm/helm
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.3 KiB
55 lines
1.3 KiB
9 years ago
|
package support
|
||
9 years ago
|
|
||
|
import "fmt"
|
||
|
|
||
9 years ago
|
// Severity indicatest the severity of a Message.
|
||
9 years ago
|
type Severity int
|
||
|
|
||
|
const (
|
||
9 years ago
|
// UnknownSev indicates that the severity of the error is unknown, and should not stop processing.
|
||
9 years ago
|
UnknownSev = iota
|
||
9 years ago
|
// InfoSev indicates information, for example missing values.yaml file
|
||
9 years ago
|
InfoSev
|
||
9 years ago
|
// WarningSev indicates that something does not meet code standards, but will likely function.
|
||
9 years ago
|
WarningSev
|
||
9 years ago
|
// ErrorSev indicates that something will not likely function.
|
||
9 years ago
|
ErrorSev
|
||
|
)
|
||
|
|
||
9 years ago
|
// sev matches the *Sev states.
|
||
9 years ago
|
var sev = []string{"UNKNOWN", "INFO", "WARNING", "ERROR"}
|
||
9 years ago
|
|
||
9 years ago
|
// Message is a linting output message
|
||
9 years ago
|
type Message struct {
|
||
|
// Severity is one of the *Sev constants
|
||
9 years ago
|
Severity Severity
|
||
9 years ago
|
// Text contains the message text
|
||
|
Text string
|
||
|
}
|
||
|
|
||
9 years ago
|
type Linter struct {
|
||
|
Messages []Message
|
||
|
ChartDir string
|
||
|
}
|
||
|
|
||
|
type LintError interface {
|
||
|
error
|
||
|
}
|
||
|
|
||
|
type ValidationFunc func(*Linter) LintError
|
||
|
|
||
9 years ago
|
// String prints a string representation of this Message.
|
||
|
//
|
||
|
// Implements fmt.Stringer.
|
||
|
func (m Message) String() string {
|
||
|
return fmt.Sprintf("[%s] %s", sev[m.Severity], m.Text)
|
||
|
}
|
||
9 years ago
|
|
||
|
// Returns true if the validation passed
|
||
|
func (l *Linter) RunLinterRule(severity Severity, lintError LintError) bool {
|
||
|
if lintError != nil {
|
||
|
l.Messages = append(l.Messages, Message{Text: lintError.Error(), Severity: severity})
|
||
|
}
|
||
|
return lintError == nil
|
||
|
}
|