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 49a42ed
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

#### Improvements 🧹

- Boards no longer inherit `label` fields from parents. [#1838](https://github.com/terrastruct/d2/pull/1838)
- Boards no longer inherit `label` fields from parents [#1838](https://github.com/terrastruct/d2/pull/1838)
- Prevents `near` targeting a child of a special object like grid cells, which wasn't doing anything [#1851](https://github.com/terrastruct/d2/pull/1851)

#### Bugfixes ⛑️

Expand Down
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 49a42ed

Please sign in to comment.