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

Allow nested 'if' instead of chained 'else if' #427

Open
ianmackenzie opened this issue Nov 12, 2017 · 0 comments
Open

Allow nested 'if' instead of chained 'else if' #427

ianmackenzie opened this issue Nov 12, 2017 · 0 comments

Comments

@ianmackenzie
Copy link

I've run into a couple of cases where elm-format has reformatted if expressions in a way that makes the logic less clear. For example, today I wanted to write some code that classified an angle as 'small positive', 'large positive', 'small negative' or 'large negative'. I tried to write it like this:

sweptAngle =
    if arcSweptAngle >= 0 then
        if arcSweptAngle <= pi then
            EllipticalArc2d.smallPositive
        else
            EllipticalArc2d.largePositive
    else
        if arcSweptAngle >= -pi then
            EllipticalArc2d.smallNegative
        else
            EllipticalArc2d.largeNegative

but elm-format changed it to

sweptAngle =
    if arcSweptAngle >= 0 then
        if arcSweptAngle <= pi then
            EllipticalArc2d.smallPositive
        else
            EllipticalArc2d.largePositive
    else if arcSweptAngle >= -pi then
        EllipticalArc2d.smallNegative
    else
        EllipticalArc2d.largeNegative

which obscures the symmetry between the positive and negative angle branches. Similar to how elm-format allows the user to decide whether to keep lists/function arguments all on one line or break them over multiple lines, would it be possible in this case to let the user decide whether if expressions should be nested or chained?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant