Merge pull request #2251 from alixander/validate-values
d2compiler: validate that reserved keywords have values
This commit is contained in:
commit
1ea36d5d39
5 changed files with 32 additions and 6 deletions
|
|
@ -13,6 +13,7 @@
|
||||||
- This is a breaking change. Previously Latex blocks required escaping the backslash. So
|
- This is a breaking change. Previously Latex blocks required escaping the backslash. So
|
||||||
for older D2 versions, you should remove the excess backslashes.
|
for older D2 versions, you should remove the excess backslashes.
|
||||||
- Links: non-http url scheme links are supported (e.g. `x.link: vscode://file/`) [#2237](https://github.com/terrastruct/d2/issues/2237)
|
- Links: non-http url scheme links are supported (e.g. `x.link: vscode://file/`) [#2237](https://github.com/terrastruct/d2/issues/2237)
|
||||||
|
- Compiler: reserved keywords with missing values error instead of silently doing nothing [#2251](https://github.com/terrastruct/d2/pull/2251)
|
||||||
|
|
||||||
#### Bugfixes ⛑️
|
#### Bugfixes ⛑️
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -239,8 +239,6 @@ func (c *compiler) compileMap(obj *d2graph.Object, m *d2ir.Map) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
c.errorf(class.LastRef().AST(), "class missing value")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, className := range classNames {
|
for _, className := range classNames {
|
||||||
|
|
@ -505,6 +503,8 @@ func (c *compiler) compileReserved(attrs *d2graph.Attributes, f *d2ir.Field) {
|
||||||
default:
|
default:
|
||||||
c.errorf(f.LastPrimaryKey(), "reserved field %v does not accept composite", f.Name.ScalarString())
|
c.errorf(f.LastPrimaryKey(), "reserved field %v does not accept composite", f.Name.ScalarString())
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
c.errorf(f.LastRef().AST(), `reserved field "%v" must have a value`, f.Name.ScalarString())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -817,8 +817,6 @@ func (c *compiler) compileEdgeMap(edge *d2graph.Edge, m *d2ir.Map) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
c.errorf(class.LastRef().AST(), "class missing value")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, className := range classNames {
|
for _, className := range classNames {
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,18 @@ x: {
|
||||||
tassert.Equal(t, "200", g.Objects[0].Top.Value)
|
tassert.Equal(t, "200", g.Objects[0].Top.Value)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "reserved_missing_values",
|
||||||
|
text: `foobar: {
|
||||||
|
width
|
||||||
|
bottom
|
||||||
|
left
|
||||||
|
right
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
expErr: `d2/testdata/d2compiler/TestCompile/reserved_missing_values.d2:2:3: reserved field "width" must have a value
|
||||||
|
d2/testdata/d2compiler/TestCompile/reserved_missing_values.d2:4:3: reserved field "left" must have a value`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "positions_negative",
|
name: "positions_negative",
|
||||||
text: `hey: {
|
text: `hey: {
|
||||||
|
|
@ -3066,7 +3078,7 @@ object: {
|
||||||
name: "no-class-primary",
|
name: "no-class-primary",
|
||||||
text: `x.class
|
text: `x.class
|
||||||
`,
|
`,
|
||||||
expErr: `d2/testdata/d2compiler/TestCompile/no-class-primary.d2:1:3: class missing value`,
|
expErr: `d2/testdata/d2compiler/TestCompile/no-class-primary.d2:1:3: reserved field "class" must have a value`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "no-class-inside-classes",
|
name: "no-class-inside-classes",
|
||||||
|
|
|
||||||
2
testdata/d2compiler/TestCompile/no-class-primary.exp.json
generated
vendored
2
testdata/d2compiler/TestCompile/no-class-primary.exp.json
generated
vendored
|
|
@ -4,7 +4,7 @@
|
||||||
"errs": [
|
"errs": [
|
||||||
{
|
{
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/no-class-primary.d2,0:2:2-0:7:7",
|
"range": "d2/testdata/d2compiler/TestCompile/no-class-primary.d2,0:2:2-0:7:7",
|
||||||
"errmsg": "d2/testdata/d2compiler/TestCompile/no-class-primary.d2:1:3: class missing value"
|
"errmsg": "d2/testdata/d2compiler/TestCompile/no-class-primary.d2:1:3: reserved field \"class\" must have a value"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
testdata/d2compiler/TestCompile/reserved_missing_values.exp.json
generated
vendored
Normal file
15
testdata/d2compiler/TestCompile/reserved_missing_values.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/reserved_missing_values.d2,1:2:12-1:7:17",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/reserved_missing_values.d2:2:3: reserved field \"width\" must have a value"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/reserved_missing_values.d2,3:2:29-3:6:33",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/reserved_missing_values.d2:4:3: reserved field \"left\" must have a value"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue