Documentation
¶
Overview ¶
Package validation provides validation rules for Spectr changes and specs.
Package validation provides validation result printing functions. This file contains functions for outputting validation results in both JSON and human-readable formats.
Package validation provides validation helper functions.
Package validation provides functions for collecting validation items.
Index ¶
- Constants
- func ContainsShallOrMust(text string) bool
- func ExtractScenarios(requirementBlock string) []string
- func ExtractSections(content string) map[string]string
- func NormalizeRequirementName(name string) string
- func PrintBulkHumanResults(results []BulkResult)
- func PrintBulkJSONResults(results []BulkResult)
- func PrintHumanReport(itemName string, report *ValidationReport)
- func PrintJSONReport(report *ValidationReport)
- func RunInteractiveValidation(projectPath string, jsonOutput bool) error
- func ToRelativePath(absPath string) string
- func ValidatePreMerge(baseSpecPath string, deltaPlan *parsers.DeltaPlan, specExists bool) error
- type BulkResult
- type DeltaType
- type ItemTypeInfo
- type RenamedRequirement
- type Requirement
- type ValidationIssue
- type ValidationItem
- type ValidationLevel
- type ValidationReport
- func NewValidationReport(issuesParam []ValidationIssue) *ValidationReport
- func ValidateChangeDeltaSpecs(changeDir string, spectrRoot string) (*ValidationReport, error)
- func ValidateItemByType(validator *Validator, projectPath, itemName, itemType string) (*ValidationReport, error)
- func ValidateSpecFile(path string) (*ValidationReport, error)
- type ValidationSummary
- type Validator
Constants ¶
const ( ColorError = "1" // Red ColorWarning = "3" // Yellow )
Color constants for validation output styling
const ( // ItemTypeChange represents a change item type ItemTypeChange = "change" // ItemTypeSpec represents a spec item type ItemTypeSpec = "spec" // SpectrDir is the base directory for spectr files SpectrDir = "spectr" )
Variables ¶
This section is empty.
Functions ¶
func ContainsShallOrMust ¶
ContainsShallOrMust checks if text contains SHALL or MUST (case-insensitive) Uses string-based matching instead of regex for better performance
func ExtractScenarios ¶
ExtractScenarios finds all #### Scenario: blocks in a requirement
func ExtractSections ¶
ExtractSections returns a map of section headers (## headers) to their content Example: "## Purpose" -> "This is the purpose..."
func NormalizeRequirementName ¶
NormalizeRequirementName normalizes requirement names for duplicate detection Trims whitespace, converts to lowercase, and removes extra spaces Uses string-based operations instead of regex for better performance
func PrintBulkHumanResults ¶
func PrintBulkHumanResults(results []BulkResult)
PrintBulkHumanResults prints bulk validation results in human format with improved formatting: visual separation between failed items, relative paths, issues grouped by file, colored error/warning labels, enhanced summary, and type indicators.
func PrintBulkJSONResults ¶
func PrintBulkJSONResults(results []BulkResult)
PrintBulkJSONResults prints bulk validation results as JSON
func PrintHumanReport ¶
func PrintHumanReport( itemName string, report *ValidationReport, )
PrintHumanReport prints a single validation report in human format
func PrintJSONReport ¶
func PrintJSONReport( report *ValidationReport, )
PrintJSONReport prints a single validation report as JSON
func RunInteractiveValidation ¶
RunInteractiveValidation runs the interactive validation TUI
func ToRelativePath ¶
ToRelativePath converts an absolute path to a path relative to the spectr/ directory. It removes everything up to and including the spectr/ prefix. Example: /home/user/project/spectr/changes/foo/spec.md -> changes/foo/spec.md
func ValidatePreMerge ¶
ValidatePreMerge validates delta operations against base spec. It checks that: - ADDED requirements don't already exist in base spec - MODIFIED/REMOVED/RENAMED requirements DO exist in base spec - RENAMED TO requirements don't already exist (unless renaming to itself)
If specExists is false, only ADDED operations are allowed.
Types ¶
type BulkResult ¶
type BulkResult struct {
Name string `json:"name"`
Type string `json:"type"`
Valid bool `json:"valid"`
Report *ValidationReport `json:"report,omitempty"`
Error string `json:"error,omitempty"`
}
BulkResult represents the result of validating a single item
func ValidateSingleItem ¶
func ValidateSingleItem( validator *Validator, item ValidationItem, ) (BulkResult, error)
ValidateSingleItem validates a single item and returns the bulk result
type ItemTypeInfo ¶
ItemTypeInfo holds information about an item's type
func DetermineItemType ¶
func DetermineItemType( projectPath, itemName string, typeFlag *string, ) (ItemTypeInfo, error)
DetermineItemType determines if an item is a change or spec
type RenamedRequirement ¶
RenamedRequirement represents a FROM -> TO rename pair
type Requirement ¶
Requirement represents a parsed requirement with its content and scenarios
func ExtractRequirements ¶
func ExtractRequirements( content string, ) []Requirement
ExtractRequirements returns all requirements found in content Looks for ### Requirement: headers
type ValidationIssue ¶
type ValidationIssue struct {
Level ValidationLevel `json:"level"`
Path string `json:"path"`
Line int `json:"line,omitempty"`
Message string `json:"message"`
}
ValidationIssue represents a single validation problem or note
type ValidationItem ¶
ValidationItem represents an item to validate
func CreateValidationItems ¶
func CreateValidationItems( _ string, ids []string, itemType, basePath string, ) []ValidationItem
CreateValidationItems creates validation items from IDs and item type. The projectPath parameter is intentionally unused for now but kept for potential future use in path construction.
func GetAllItems ¶
func GetAllItems( projectPath string, ) ([]ValidationItem, error)
GetAllItems returns all changes and specs from the project path.
func GetChangeItems ¶
func GetChangeItems( projectPath string, ) ([]ValidationItem, error)
GetChangeItems returns all changes from the project path.
func GetSpecItems ¶
func GetSpecItems( projectPath string, ) ([]ValidationItem, error)
GetSpecItems returns all specs from the project path.
type ValidationLevel ¶
type ValidationLevel string
ValidationLevel represents the severity of a validation issue
const ( // LevelError indicates a critical validation failure LevelError ValidationLevel = "ERROR" // LevelWarning indicates a non-critical issue that should be addressed LevelWarning ValidationLevel = "WARNING" // LevelInfo provides informational feedback LevelInfo ValidationLevel = "INFO" )
type ValidationReport ¶
type ValidationReport struct {
Valid bool `json:"valid"`
Issues []ValidationIssue `json:"issues"`
Summary ValidationSummary `json:"summary"`
}
ValidationReport contains the complete validation results for an item
func NewValidationReport ¶
func NewValidationReport( issuesParam []ValidationIssue, ) *ValidationReport
NewValidationReport creates a new ValidationReport from a list of issues
func ValidateChangeDeltaSpecs ¶
func ValidateChangeDeltaSpecs( changeDir string, spectrRoot string, ) (*ValidationReport, error)
ValidateChangeDeltaSpecs validates all delta spec files in a change directory. changeDir should be the path to a change directory (e.g., spectr/changes/add-feature). spectrRoot should be the path to the spectr/ directory (e.g., /path/to/project/spectr). Returns ValidationReport with all issues found, or error for issues. Validation is always strict: warnings are converted to errors.
func ValidateItemByType ¶
func ValidateItemByType( validator *Validator, projectPath, itemName, itemType string, ) (*ValidationReport, error)
ValidateItemByType validates an item based on its type
func ValidateSpecFile ¶
func ValidateSpecFile( path string, ) (*ValidationReport, error)
ValidateSpecFile validates a spec file according to Spectr rules Returns a ValidationReport containing all issues found, or an error for filesystem issues Note: Always applies strict validation (warnings are converted to errors)
type ValidationSummary ¶
type ValidationSummary struct {
Errors int `json:"errors"`
Warnings int `json:"warnings"`
Info int `json:"info"`
}
ValidationSummary provides aggregate counts of validation issues
type Validator ¶
type Validator struct{}
Validator is the main orchestrator for validation operations. It coordinates validation of specs and changes using the underlying rule functions.
func NewValidator ¶
func NewValidator() *Validator
NewValidator creates a new Validator. Validation always treats warnings as errors (strict mode).
func (*Validator) CreateReport ¶
func (*Validator) CreateReport( issues []ValidationIssue, ) *ValidationReport
CreateReport creates a ValidationReport from a list of issues. This is a helper method for creating validation reports. Warnings are converted to errors by the underlying validation functions before reaching this point (validation is always strict).
func (*Validator) ValidateChange ¶
func (*Validator) ValidateChange( changeDir string, ) (*ValidationReport, error)
ValidateChange validates all delta spec files in a change directory. This is a wrapper around ValidateChangeDeltaSpecs that always validates strictly. changeDir should be the path to a change directory (e.g., spectr/changes/add-feature). Returns a ValidationReport with all issues found, or an error for filesystem issues.
func (*Validator) ValidateSpec ¶
func (*Validator) ValidateSpec( path string, ) (*ValidationReport, error)
ValidateSpec validates a specification file at the given path. This is a wrapper around ValidateSpecFile that always validates strictly. Returns a ValidationReport with all issues found, or an error for filesystem issues.