DSLX formatter does not provide a way to precisely comment on an else condition
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
**Describe the bug**
The formatter either removes the comment or moves it inside the branch, which can be misleading.
**To Reproduce**
Steps to reproduce the behavior:
```
fn foo(x: u1) -> u32 {
if x {
u32:42
} else { // we take the else branch because
u32:0
}
}
```
is formatted to
```
fn foo(x: u1) -> u32 {
if x {
u32:42
} else {
// we take the else branch because
u32:0
}
}
```
That can be misleading as the comment is indented to match the return value here. As an attempted workaround,
```
fn foo(x: u1) -> u32 {
if x {
u32:42
}
// we take the else branch because
else {
u32:0
}
}
```
is formatted to:
```
fn foo(x: u1) -> u32 {
if x { u32:42 } else { u32:0 }
}
```
**Expected behavior**
Preserve the comment
Contributor guide
Assessment
This issue has not been assessed yet.