Skip to content

Commit

Permalink
remove empty board keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Oct 27, 2024
1 parent efd401a commit ef52ce0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Lib: removes a dependency on external slog that was causing troubles with installation [#2137](https://github.com/terrastruct/d2/pull/2137)
- CLI: attempts writing to path atomically, falling back to non-atomic if failed [#2141](https://github.com/terrastruct/d2/pull/2141)
- Export: pptx has "created at" metadata removed, so successive runs yield the same result [#2169](https://github.com/terrastruct/d2/pull/2160)
- Formatter: empty board keywords (e.g. `layers`) are removed [#2169](https://github.com/terrastruct/d2/pull/2160)

#### Bugfixes ⛑️

Expand Down
13 changes: 10 additions & 3 deletions d2format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,18 @@ func (p *printer) _map(m *d2ast.Map) {
if nb.IsBoardNode() {
switch nb.MapKey.Key.Path[0].Unbox().ScalarString() {
case "layers":
layerNodes = append(layerNodes, nb)
// remove useless
if nb.MapKey.Value.Map != nil && len(nb.MapKey.Value.Map.Nodes) > 0 {
layerNodes = append(layerNodes, nb)
}
case "scenarios":
scenarioNodes = append(scenarioNodes, nb)
if nb.MapKey.Value.Map != nil && len(nb.MapKey.Value.Map.Nodes) > 0 {
scenarioNodes = append(scenarioNodes, nb)
}
case "steps":
stepNodes = append(stepNodes, nb)
if nb.MapKey.Value.Map != nil && len(nb.MapKey.Value.Map.Nodes) > 0 {
stepNodes = append(stepNodes, nb)
}
}
prev = n
continue
Expand Down
11 changes: 11 additions & 0 deletions d2format/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,17 @@ coop: {
fill: blue
}
}
`,
},
{
name: "remove-empty-boards",
in: `k
layers
scenarios: {}
steps: asdf
`,
exp: `k
`,
},
}
Expand Down

0 comments on commit ef52ce0

Please sign in to comment.