Documentation
¶
Index ¶
- Constants
- Variables
- func Colorize(color, text string) string
- func Dim(format string, a ...interface{}) string
- func EnableColor(enable bool)
- func Error(format string, a ...interface{}) string
- func FormatTable(table [][]string, headerRow bool) [][]string
- func Header(format string, a ...interface{}) string
- func Highlight(format string, a ...interface{}) string
- func Info(format string, a ...interface{}) string
- func IsColorEnabled() bool
- func Label(key, value string) string
- func PTermStatusLabel(status string) string
- func PrintLintSummary(fileCount, errorCount, fixCount int, duration time.Duration)
- func PrintSuccess(message string)
- func StatusLabel(status string) string
- func StatusSymbol(success bool) string
- func Success(format string, a ...interface{}) string
- func Warning(format string, a ...interface{}) string
- type ErrorFormatter
- func (f *ErrorFormatter) AddError(err ValidationError)
- func (f *ErrorFormatter) ExtractFieldName(errStr string) string
- func (f *ErrorFormatter) ExtractLineNumber(errStr string) int
- func (f *ErrorFormatter) FormatAsJSON() string
- func (f *ErrorFormatter) GenerateHint(errStr, errType string) string
- func (f *ErrorFormatter) PrintError(errStr string, lineNum int)
- func (f *ErrorFormatter) PrintErrorHeader()
- func (f *ErrorFormatter) PrintErrorSummary()
- func (f *ErrorFormatter) PrintServiceError(serviceName, errStr string, lineNum int)
- func (f *ErrorFormatter) TryAutoFix(errStr string, lineNum int) (bool, []byte)
- type ValidationError
Constants ¶
const ( Reset = "\033[0m" Bold = "\033[1m" Red = "\033[31m" Green = "\033[32m" Yellow = "\033[33m" Blue = "\033[34m" DarkBlue = "\033[34;1m" Magenta = "\033[35m" Cyan = "\033[36m" White = "\033[37m" BoldRed = "\033[1;31m" BoldGreen = "\033[1;32m" BoldYellow = "\033[1;33m" BoldBlue = "\033[1;34m" BoldCyan = "\033[1;36m" )
Color codes
const ( ErrorType = "error" WarningType = "warning" InfoType = "info" )
Error types
Variables ¶
var ( ErrorColor = color.New(color.FgRed, color.Bold) WarningColor = color.New(color.FgYellow, color.Bold) SuccessColor = color.New(color.FgGreen, color.Bold) FileColor = color.New(color.FgCyan) LineColor = color.New(color.FgHiGreen) CodeColor = color.New(color.FgWhite) ContextColor = color.New(color.FgHiBlack) HintColor = color.New(color.FgYellow, color.Italic) HeadingColor = color.New(color.FgHiWhite, color.Bold) HighlightColor = color.New(color.FgHiRed) )
Error colors
var ErrorCategoryMapping = map[string]string{
"invalid YAML": "YAML_SYNTAX",
"field validation failed": "FIELD_VALIDATION",
"missing required field": "MISSING_FIELD",
"invalid value": "INVALID_VALUE",
"unknown field": "UNKNOWN_FIELD",
"duplicate field": "DUPLICATE_FIELD",
"unexpected format": "FORMAT_ERROR",
"check indentation": "INDENTATION_ERROR",
"reference error": "REFERENCE_ERROR",
"unrecognized resource type": "UNKNOWN_RESOURCE",
"must be between": "RANGE_ERROR",
"cannot be negative": "NEGATIVE_VALUE",
"is required": "MISSING_REQUIRED",
"must specify": "MISSING_SPECIFICATION",
"must have": "MISSING_REQUIREMENT",
}
ErrorCategoryMapping maps error patterns to categories
Functions ¶
func EnableColor ¶
func EnableColor(enable bool)
EnableColor enables or disables colored output globally
func FormatTable ¶
FormatTable colorizes a table of strings based on a header row
func IsColorEnabled ¶
func IsColorEnabled() bool
IsColorEnabled returns whether colored output is enabled
func PTermStatusLabel ¶
PTermStatusLabel applies consistent coloring to status strings based on their value
func PrintLintSummary ¶
PrintLintSummary prints a summary of the linting process
func StatusLabel ¶
StatusLabel formats a status label based on the status value
func StatusSymbol ¶
StatusSymbol returns a colorized status symbol
Types ¶
type ErrorFormatter ¶
type ErrorFormatter struct {
FileName string
FileData []byte
ContextLines int
CanAutoFix bool
OutputFormat string
Errors []ValidationError
StartTime time.Time
TerminalWidth int
ErrorCount int
WarningCount int
FixCount int
}
ErrorFormatter is used to format and print error messages
func NewErrorFormatter ¶
func NewErrorFormatter(filename string, data []byte) *ErrorFormatter
NewErrorFormatter creates a new error formatter
func (*ErrorFormatter) AddError ¶
func (f *ErrorFormatter) AddError(err ValidationError)
AddError adds a new error to the formatter
func (*ErrorFormatter) ExtractFieldName ¶
func (f *ErrorFormatter) ExtractFieldName(errStr string) string
ExtractFieldName tries to extract a field name from an error message
func (*ErrorFormatter) ExtractLineNumber ¶
func (f *ErrorFormatter) ExtractLineNumber(errStr string) int
ExtractLineNumber tries to extract a line number from an error message
func (*ErrorFormatter) FormatAsJSON ¶
func (f *ErrorFormatter) FormatAsJSON() string
FormatAsJSON formats all errors as a JSON string
func (*ErrorFormatter) GenerateHint ¶
func (f *ErrorFormatter) GenerateHint(errStr, errType string) string
GenerateHint creates a hint based on the error message
func (*ErrorFormatter) PrintError ¶
func (f *ErrorFormatter) PrintError(errStr string, lineNum int)
PrintError prints an error with context
func (*ErrorFormatter) PrintErrorHeader ¶
func (f *ErrorFormatter) PrintErrorHeader()
PrintErrorHeader prints a header for errors
func (*ErrorFormatter) PrintErrorSummary ¶
func (f *ErrorFormatter) PrintErrorSummary()
PrintErrorSummary prints a summary of all errors categorized by type
func (*ErrorFormatter) PrintServiceError ¶
func (f *ErrorFormatter) PrintServiceError(serviceName, errStr string, lineNum int)
PrintServiceError prints an error specific to a service
func (*ErrorFormatter) TryAutoFix ¶
func (f *ErrorFormatter) TryAutoFix(errStr string, lineNum int) (bool, []byte)
TryAutoFix attempts to fix common errors
type ValidationError ¶
type ValidationError struct {
FileName string `json:"file_name"`
LineNumber int `json:"line_number"`
Message string `json:"message"`
ErrorType string `json:"error_type"`
Hint string `json:"hint,omitempty"`
AutoFixable bool `json:"auto_fixable"`
FixApplied bool `json:"fix_applied"`
ResourceName string `json:"resource_name,omitempty"`
ResourceType string `json:"resource_type,omitempty"`
Context string `json:"context,omitempty"`
}
ValidationError represents a structured validation error