Skip to content

Commit

Permalink
give err msg for invalid edge style
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Mar 7, 2023
1 parent 4e53c27 commit d4cfc67
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions d2compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,11 @@ func (c *compiler) compileEdge(obj *d2graph.Object, e *d2ir.Edge) {

func (c *compiler) compileEdgeField(edge *d2graph.Edge, f *d2ir.Field) {
keyword := strings.ToLower(f.Name)
_, isStyleReserved := d2graph.StyleKeywords[keyword]
if isStyleReserved {
c.errorf(f.LastRef().AST(), "%v must be style.%v", f.Name, f.Name)
return
}
_, isReserved := d2graph.SimpleReservedKeywords[keyword]
if isReserved {
c.compileReserved(edge.Attributes, f)
Expand Down
18 changes: 18 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,24 @@ x: {
`,
expErr: `d2/testdata/d2compiler/TestCompile/shape_edge_style.d2:3:2: key "animated" can only be applied to edges`,
},
{
name: "edge_invalid_style",

text: `x -> y: {
opacity: 0.5
}
`,
expErr: `d2/testdata/d2compiler/TestCompile/edge_invalid_style.d2:2:3: opacity must be style.opacity`,
},
{
name: "obj_invalid_style",

text: `x: {
opacity: 0.5
}
`,
expErr: `d2/testdata/d2compiler/TestCompile/obj_invalid_style.d2:2:3: opacity must be style.opacity`,
},
{
name: "edge_chain_map",

Expand Down
12 changes: 12 additions & 0 deletions testdata/d2compiler/TestCompile/edge_invalid_style.exp.json

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

12 changes: 12 additions & 0 deletions testdata/d2compiler/TestCompile/obj_invalid_style.exp.json

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

0 comments on commit d4cfc67

Please sign in to comment.