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

Idempotency problem with nested else if #1648

Closed
Smaug123 opened this issue Apr 15, 2021 · 3 comments
Closed

Idempotency problem with nested else if #1648

Smaug123 opened this issue Apr 15, 2021 · 3 comments

Comments

@Smaug123
Copy link
Contributor

Too big for GitHub's query string, sorry.

Input

module Foo =

    let private Blah () =
        let applied, errors =
            things
            |> Seq.choose (fun r ->
                Map.tryFind r otherStuff
                |> Option.map (fun s ->
                    let result, output = execute s
                    if result.LaunchSuccess && result.ExitCode = 0 then Ok r else
                    if result.ExitCode = 1 then
                        let stdout, stderr = output |> List.map (function | StdErr e -> Error e | StdOut l -> Ok l) |> Result.partition
                        if not stderr.IsEmpty then
                            failwithf "Got stderr bad bad bad"
                        match stdout with
                        | [] ->
                            failwithf "Got no stdout :("
                        | xs when xs |> List.exists (fun i -> i.Contains "magic string goes here!") ->
                            Error (Ok r)
                        | _ -> Error (Error r)
                    else
                        failwith ""
                )
            )
        failwith ""

Output

module Foo =

    let private Blah () =
        let applied, errors =
            things
            |> Seq.choose (fun r ->
                Map.tryFind r otherStuff
                |> Option.map (fun s ->
                    let result, output = execute s

                    if result.LaunchSuccess && result.ExitCode = 0 then
                        Ok r
                    else if result.ExitCode = 1 then
                        let stdout, stderr =
                            output
                            |> List.map
                                (function
                                | StdErr e -> Error e
                                | StdOut l -> Ok l)
                            |> Result.partition

                        if not stderr.IsEmpty then
                            failwithf "Got stderr bad bad bad"

                        match stdout with
                        | [] -> failwithf "Got no stdout :("
                        | xs when
                            xs
                            |> List.exists (fun i -> i.Contains "magic string goes here!")
                            ->
                            Error (Ok r)
                        | _ -> Error (Error r)
                    else
                        failwith ""
                )
            )

        failwith ""

Reformatted output

module Foo =

    let private Blah () =
        let applied, errors =
            things
            |> Seq.choose (fun r ->
                Map.tryFind r otherStuff
                |> Option.map (fun s ->
                    let result, output = execute s

                    if result.LaunchSuccess && result.ExitCode = 0 then
                        Ok r
                    else

                    if result.ExitCode = 1 then
                        let stdout, stderr =
                            output
                            |> List.map
                                (function
                                | StdErr e -> Error e
                                | StdOut l -> Ok l)
                            |> Result.partition

                        if not stderr.IsEmpty then
                            failwithf "Got stderr bad bad bad"

                        match stdout with
                        | [] -> failwithf "Got no stdout :("
                        | xs when
                            xs
                            |> List.exists (fun i -> i.Contains "magic string goes here!")
                            ->
                            Error (Ok r)
                        | _ -> Error (Error r)
                    else
                        failwith ""
                )
            )

        failwith ""

Notice that we've split an else if over another line. (But the reformatted version does correctly unindent the body of the else, so that's something!)

Settings

[*.fs]
fsharp_space_before_uppercase_invocation=true
fsharp_space_before_class_constructor=true
fsharp_space_before_member=true
fsharp_space_before_colon=true
fsharp_space_before_semicolon=true
fsharp_multiline_block_brackets_on_same_column=true
fsharp_newline_between_type_definition_and_members=true
fsharp_keep_if_then_in_same_line=true
fsharp_align_function_signature_to_indentation=true
fsharp_alternative_long_member_definitions=true
fsharp_multi_line_lambda_closing_newline=true
fsharp_keep_indent_in_branch=true
@Smaug123 Smaug123 changed the title Idempotency problem Idempotency problem with nested else if Apr 15, 2021
@nojaf
Copy link
Contributor

nojaf commented Apr 16, 2021

Just so we are on the same page, based on the input I would expect fsharp_keep_indent_in_branch not to be in play here right?
As the long else if is well not the else branch so it shouldn't match the shape right?

@Smaug123
Copy link
Contributor Author

You're quite right - it would be a compile error to unindent that else if because there's an else after it.

@nojaf
Copy link
Contributor

nojaf commented May 8, 2021

Thanks, closing via #1659.

@nojaf nojaf closed this as completed May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants