Move scene shape facts into the scene family
This commit is contained in:
@@ -11,8 +11,8 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
scenefacts "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/scenedescriptions"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared/diagnostics"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/validate/scenedescriptions/shape"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -81,8 +81,8 @@ func normalizeList(input dnd.SceneDescriptionList, doc *source.SourceDocument) (
|
||||
originalTitle, originalSummary := scene.Title, scene.Summary
|
||||
scene.Title = strings.TrimSpace(scene.Title)
|
||||
scene.Summary = strings.TrimSpace(scene.Summary)
|
||||
if err := shape.Validate(dnd.SceneDescriptionList{Scenes: []dnd.SceneDescription{scene}}); err != nil {
|
||||
return dnd.SceneDescriptionList{}, nil, fmt.Errorf("scenes[%d]: %w", sceneIndex, err)
|
||||
if facts := scenefacts.Check(dnd.SceneDescriptionList{Scenes: []dnd.SceneDescription{scene}}); len(facts) != 0 {
|
||||
return dnd.SceneDescriptionList{}, nil, fmt.Errorf("scenes[%d]: %s", sceneIndex, describeShapeFacts(scene, facts))
|
||||
}
|
||||
if err := documentIndex.ValidateRef(scene.SourceRef); err != nil {
|
||||
return dnd.SceneDescriptionList{}, nil, fmt.Errorf("scenes[%d].source_ref: %s", sceneIndex, diagnostics.Truncate(err.Error()))
|
||||
@@ -146,6 +146,26 @@ func normalizeList(input dnd.SceneDescriptionList, doc *source.SourceDocument) (
|
||||
return dnd.SceneDescriptionList{Scenes: unique}, findings, nil
|
||||
}
|
||||
|
||||
func describeShapeFacts(scene dnd.SceneDescription, facts []scenefacts.Issue) string {
|
||||
issues := make([]string, 0, len(facts))
|
||||
for _, fact := range facts {
|
||||
prefix := fmt.Sprintf("scenes[%d]", fact.Index)
|
||||
switch fact.Field {
|
||||
case scenefacts.ID:
|
||||
issues = append(issues, prefix+".id must be non-empty and trimmed")
|
||||
case scenefacts.Kind:
|
||||
issues = append(issues, prefix+".kind is unsupported: "+diagnostics.Quote(string(scene.Kind)))
|
||||
case scenefacts.Title:
|
||||
issues = append(issues, prefix+".title must be non-empty and trimmed")
|
||||
case scenefacts.Summary:
|
||||
issues = append(issues, prefix+".summary must be non-empty and trimmed")
|
||||
case scenefacts.SourceRef:
|
||||
issues = append(issues, prefix+".source_ref must have a trimmed source ID and positive unit IDs")
|
||||
}
|
||||
}
|
||||
return diagnostics.Aggregate("invalid scene description shape", issues)
|
||||
}
|
||||
|
||||
func sceneScope(index int) string { return fmt.Sprintf("scenes[%d]", index) }
|
||||
|
||||
func identical(left, right dnd.SceneDescription) bool {
|
||||
|
||||
Reference in New Issue
Block a user