Skip to content

Commit

Permalink
Merge pull request #2178 from alixander/fmt-board-vars
Browse files Browse the repository at this point in the history
d2fmt: remove empty board keywords
  • Loading branch information
alixander authored Oct 27, 2024
2 parents efd401a + 17846b4 commit c775a9b
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 [#2178](https://github.com/terrastruct/d2/pull/2178)

#### 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 c775a9b

Please sign in to comment.