preserve comment spacing in autofmt
This commit is contained in:
parent
e993bb1071
commit
a354ae574e
3 changed files with 21 additions and 1 deletions
|
|
@ -5,6 +5,9 @@
|
||||||
|
|
||||||
#### Improvements 🧹
|
#### Improvements 🧹
|
||||||
|
|
||||||
|
- Fmt now preserves leading comment spacing.
|
||||||
|
[#400](https://github.com/terrastruct/d2/issues/400)
|
||||||
|
|
||||||
#### Bugfixes ⛑️
|
#### Bugfixes ⛑️
|
||||||
|
|
||||||
- Fixed crash when sequence diagrams had no messages.
|
- Fixed crash when sequence diagrams had no messages.
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ func (p *printer) comment(c *d2ast.Comment) {
|
||||||
lines := strings.Split(c.Value, "\n")
|
lines := strings.Split(c.Value, "\n")
|
||||||
for i, line := range lines {
|
for i, line := range lines {
|
||||||
p.sb.WriteString("#")
|
p.sb.WriteString("#")
|
||||||
if line != "" && !strings.HasPrefix(line, " ") {
|
if line != "" {
|
||||||
p.sb.WriteByte(' ')
|
p.sb.WriteByte(' ')
|
||||||
}
|
}
|
||||||
p.sb.WriteString(line)
|
p.sb.WriteString(line)
|
||||||
|
|
|
||||||
|
|
@ -592,6 +592,23 @@ hi # Fraud is the homage that force pays to reason.
|
||||||
in: `x: {}
|
in: `x: {}
|
||||||
`,
|
`,
|
||||||
exp: `x
|
exp: `x
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "leading_space_comments",
|
||||||
|
in: `# foo
|
||||||
|
# foobar
|
||||||
|
# baz
|
||||||
|
x -> y
|
||||||
|
#foo
|
||||||
|
y
|
||||||
|
`,
|
||||||
|
exp: `# foo
|
||||||
|
# foobar
|
||||||
|
# baz
|
||||||
|
x -> y
|
||||||
|
# foo
|
||||||
|
y
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue