validate empty text labels

This commit is contained in:
Gavin Nishizawa 2023-09-18 13:57:37 -07:00
parent 731a7df195
commit 75ad59838b
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
2 changed files with 14 additions and 6 deletions

View file

@ -1001,11 +1001,16 @@ func (c *compiler) validateKey(obj *d2graph.Object, f *d2ir.Field) {
func (c *compiler) validateLabels(g *d2graph.Graph) {
for _, obj := range g.Objects {
if obj.Shape.Value == d2target.ShapeText {
if strings.TrimSpace(obj.Label.Value) == "" {
c.errorf(obj.Label.MapKey, "text must have a label")
continue
}
if obj.Shape.Value != d2target.ShapeText {
continue
}
if obj.Attributes.Language != "" {
// blockstrings have already been validated
continue
}
if strings.TrimSpace(obj.Label.Value) == "" {
c.errorf(obj.Label.MapKey, "shape text must have a non-empty label")
continue
}
}
}

View file

@ -2720,7 +2720,6 @@ object: {
b: " \n " {
shape: text
}
c: "" {
shape: text
}
@ -2728,6 +2727,10 @@ d: "" {
shape: circle
}
e: " \n "
f: |md |
g: |md
|
`,
expErr: `
`,