validate text shape labels
This commit is contained in:
parent
b84a51e1c0
commit
731a7df195
2 changed files with 32 additions and 0 deletions
|
|
@ -82,6 +82,7 @@ func (c *compiler) compileBoard(g *d2graph.Graph, ir *d2ir.Map) *d2graph.Graph {
|
|||
if len(c.err.Errors) == 0 {
|
||||
c.validateKeys(g.Root, ir)
|
||||
}
|
||||
c.validateLabels(g)
|
||||
c.validateNear(g)
|
||||
c.validateEdges(g)
|
||||
|
||||
|
|
@ -998,6 +999,17 @@ 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *compiler) validateNear(g *d2graph.Graph) {
|
||||
for _, obj := range g.Objects {
|
||||
if obj.NearKey != nil {
|
||||
|
|
|
|||
|
|
@ -2712,6 +2712,26 @@ object: {
|
|||
`,
|
||||
expErr: `d2/testdata/d2compiler/TestCompile/reserved-composite.d2:1:1: reserved field shape does not accept composite`,
|
||||
},
|
||||
{
|
||||
name: "text_no_label",
|
||||
text: `a: "ok" {
|
||||
shape: text
|
||||
}
|
||||
b: " \n " {
|
||||
shape: text
|
||||
}
|
||||
|
||||
c: "" {
|
||||
shape: text
|
||||
}
|
||||
d: "" {
|
||||
shape: circle
|
||||
}
|
||||
e: " \n "
|
||||
`,
|
||||
expErr: `
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
|
|
|||
Loading…
Reference in a new issue