Documentation
¶
Overview ¶
Package validator provides validation and auto-fixing for state machine configurations.
Index ¶
- Variables
- func ApplyFixes(config *statemachine.Config, fixes []*Fix) error
- func RegisterRule(rule Rule)
- type Fix
- type Location
- type Rule
- type RuleResult
- type Severity
- type Suggestion
- type ValidationError
- type ValidationResult
- func Validate(config *statemachine.Config) ValidationResult
- func ValidateFile(path string) (ValidationResult, error)
- func ValidateFileStrict(path string) (ValidationResult, error)
- func ValidateFileWithOptions(path string, strict bool) (ValidationResult, error)
- func ValidateWithRules(config *statemachine.Config, rules []Rule) ValidationResult
- func ValidateWithRulesStrict(config *statemachine.Config, rules []Rule) ValidationResult
- type ValidationWarning
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTransitionExists is returned when attempting to add a transition that already exists. ErrTransitionExists = errors.New("transition already exists") // ErrStateNotFound is returned when attempting to remove a state that doesn't exist. ErrStateNotFound = errors.New("state not found") // ErrDuplicateNotFound is returned when attempting to remove a duplicate that doesn't exist. ErrDuplicateNotFound = errors.New("duplicate not found") // ErrStateAlreadyExists is returned when attempting to rename to an existing state name. ErrStateAlreadyExists = errors.New("state already exists") // ErrAlreadyFinalState is returned when attempting to mark a state as final that already is. ErrAlreadyFinalState = errors.New("already a final state") )
var RegisteredRules []Rule
RegisteredRules stores custom validation rules.
Functions ¶
func ApplyFixes ¶
func ApplyFixes(config *statemachine.Config, fixes []*Fix) error
ApplyFixes applies a list of fixes to a config.
Types ¶
type Fix ¶
type Fix struct {
Description string
Apply func(config *statemachine.Config) error
}
Fix represents an automatic fix for a validation error.
func AddMissingTransition ¶
AddMissingTransition creates a fix that adds a transition between states.
func MarkAsFinalState ¶
MarkAsFinalState creates a fix that marks a state as final.
func RemoveDuplicateTransition ¶
RemoveDuplicateTransition creates a fix that removes a duplicate transition.
func RemoveUnreachableState ¶
RemoveUnreachableState creates a fix that removes an unreachable state.
func RenameState ¶
RenameState creates a fix that renames a state.
type Location ¶
type Location struct {
File string // Config file path
Line int // Line number (0 if unknown)
Column int // Column number (0 if unknown)
State string // State name if applicable
}
Location identifies where an issue occurred.
type Rule ¶
type Rule interface {
Name() string
Severity() Severity
Check(config *statemachine.Config) RuleResult
}
Rule defines a validation rule that can check a config for specific issues.
func DefaultRules ¶
func DefaultRules() []Rule
DefaultRules returns the standard set of validation rules.
type RuleResult ¶
type RuleResult struct {
Errors []ValidationError
Warnings []ValidationWarning
}
RuleResult contains both errors and warnings from a rule check.
type Suggestion ¶
type Suggestion struct {
Message string // Suggestion description
Example string // Code example showing the improvement
}
Suggestion provides improvement recommendations.
type ValidationError ¶
type ValidationError struct {
Code string // Error code like "UNREACHABLE_STATE", "MISSING_TRANSITION"
Message string // Human-readable error message
Location Location // Where the error occurred
Fix *Fix // Optional auto-fix suggestion
}
ValidationError represents a validation error with fix suggestions.
func ValidateOTELInstrumentation ¶
func ValidateOTELInstrumentation(config *statemachine.Config) []ValidationError
ValidateOTELInstrumentation checks that spans are created correctly. This validator ensures that the state machine is properly instrumented for OpenTelemetry tracing.
type ValidationResult ¶
type ValidationResult struct {
Valid bool
Errors []ValidationError
Warnings []ValidationWarning
Suggestions []Suggestion
}
ValidationResult contains the results of validating a state machine config.
func Validate ¶
func Validate(config *statemachine.Config) ValidationResult
Validate performs comprehensive validation on a state machine config.
func ValidateFile ¶
func ValidateFile(path string) (ValidationResult, error)
ValidateFile loads a config from a file and validates it.
func ValidateFileStrict ¶
func ValidateFileStrict(path string) (ValidationResult, error)
ValidateFileStrict loads a config from a file and validates it in strict mode.
func ValidateFileWithOptions ¶
func ValidateFileWithOptions(path string, strict bool) (ValidationResult, error)
ValidateFileWithOptions loads a config from a file and validates it with options.
func ValidateWithRules ¶
func ValidateWithRules(config *statemachine.Config, rules []Rule) ValidationResult
ValidateWithRules validates using custom rules.
func ValidateWithRulesStrict ¶
func ValidateWithRulesStrict(config *statemachine.Config, rules []Rule) ValidationResult
ValidateWithRulesStrict validates with strict mode (treats warnings as errors).
func (ValidationResult) HasErrors ¶
func (r ValidationResult) HasErrors() bool
HasErrors returns true if the result has any errors.
func (ValidationResult) HasWarnings ¶
func (r ValidationResult) HasWarnings() bool
HasWarnings returns true if the result has any warnings.
func (ValidationResult) String ¶
func (r ValidationResult) String() string
String returns a human-readable summary of validation results.
type ValidationWarning ¶
type ValidationWarning struct {
Code string // Warning code
Message string // Human-readable warning message
Location Location // Where the warning occurred
}
ValidationWarning represents a non-critical issue.
func ValidateOTELContextMetadata ¶
func ValidateOTELContextMetadata(ctx *statemachine.Context) []ValidationWarning
ValidateOTELContextMetadata validates that the Context has required metadata for span attributes. This is a runtime validation that should be called after Context is created. Returns warnings, not errors, since missing metadata doesn't prevent execution.
func ValidateOTELDebugMode ¶
func ValidateOTELDebugMode() []ValidationWarning
ValidateOTELDebugMode validates that debug mode is properly configured.