Skip to content

Commit

Permalink
prevent near special
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Feb 27, 2024
1 parent 68a9af9 commit d35ac71
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions d2compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,14 @@ func (c *compiler) validateNear(g *d2graph.Graph) {
continue
}
}
if nearObj.ClosestGridDiagram() != nil {
c.errorf(obj.NearKey, "near keys cannot be set to descendants of special objects, like grid cells")
continue
}
if nearObj.OuterSequenceDiagram() != nil {
c.errorf(obj.NearKey, "near keys cannot be set to descendants of special objects, like sequence diagram actors")
continue
}
} else if isConst {
if obj.Parent != g.Root {
c.errorf(obj.NearKey, "constant near keys can only be set on root level shapes")
Expand Down
11 changes: 11 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,17 @@ d2/testdata/d2compiler/TestCompile/near-invalid.d2:14:9: near keys cannot be set
`,
expErr: `d2/testdata/d2compiler/TestCompile/near_bad_constant.d2:1:9: near key "txop-center" must be the absolute path to a shape or one of the following constants: top-left, top-center, top-right, center-left, center-right, bottom-left, bottom-center, bottom-right`,
},
{
name: "near_special",

text: `x.near: z.x
z: {
grid-rows: 1
x
}
`,
expErr: `d2/testdata/d2compiler/TestCompile/near_special.d2:1:9: near keys cannot be set to descendants of special objects, like grid cells`,
},
{
name: "near_bad_connected",

Expand Down
11 changes: 11 additions & 0 deletions testdata/d2compiler/TestCompile/near_special.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d35ac71

Please sign in to comment.