Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSLX formatter does not provide a way to precisely comment on an else condition #1676

Open
mikex-oss opened this issue Oct 30, 2024 · 0 comments
Labels
dslx:fmt DSLX auto-formatter

Comments

@mikex-oss
Copy link
Collaborator

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

@mikex-oss mikex-oss added the dslx:fmt DSLX auto-formatter label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dslx:fmt DSLX auto-formatter
Projects
None yet
Development

No branches or pull requests

1 participant