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 ifdef in a function #1646

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

Idempotency problem with ifdef in a function #1646

Smaug123 opened this issue Apr 15, 2021 · 3 comments

Comments

@Smaug123
Copy link
Contributor

Issue created from fantomas-online

Formatted code

module Foo =
    [<Foo>]
    let blah<'a> config : Type =
#if DEBUG
        failwith ""
#endif
        DoThing.doIt ()
        let result = Runner.Run<'a> config

        if successful |> List.isEmpty then
            result
        else

        let errors =
            unsuccessful
            |> List.filter (fun report ->
                not report.BuildResult.IsBuildSuccess
                || not report.BuildResult.IsGenerateSuccess
            )
            |> List.map (fun report -> report.BuildResult.ErrorMessage)

        failwith ""

Reformatted code

module Foo =
    [<Foo>]
    let blah<'a> config : Type =
#if DEBUG
        failwith ""
#endif
        DoThing.doIt ()

        let result = Runner.Run<'a> config

        if successful |> List.isEmpty then
            result
        else

            let errors =
                unsuccessful
                |> List.filter (fun report ->
                    not report.BuildResult.IsBuildSuccess
                    || not report.BuildResult.IsGenerateSuccess
                )
                |> List.map (fun report -> report.BuildResult.ErrorMessage)

            failwith ""

Problem description

This idempotency failure goes away when I remove the #if DEBUG and its contents.

Extra information

  • The formatted result breaks by code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.

Options

Fantomas Master at 04/14/2021 13:41:07 - e164e23

    { config with
                SpaceBeforeUppercaseInvocation = true
                SpaceBeforeClassConstructor = true
                SpaceBeforeMember = true
                SpaceBeforeColon = true
                SpaceBeforeSemicolon = true
                MultilineBlockBracketsOnSameColumn = true
                NewlineBetweenTypeDefinitionAndMembers = true
                KeepIfThenInSameLine = true
                AlignFunctionSignatureToIndentation = true
                AlternativeLongMemberDefinitions = true
                MultiLineLambdaClosingNewline = true
                KeepIndentInBranch = true }

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

@Smaug123
Copy link
Contributor Author

Smaug123 commented Apr 15, 2021

Looks like two different problems here. There's the insertion of a newline below doIt, and there's the re-indentation of the KeepIndentInBranch code (which was correctly indented after the first format).

The original code was:

module Foo =
    [<Foo>]
    let blah<'a> config : Type =
        DoThing.doIt ()
        let result = Runner.Run<'a> config
        
        if successful |> List.isEmpty then
            result
        else
            let errors =
                unsuccessful
                |> List.filter
                    (fun report -> not report.BuildResult.IsBuildSuccess || not report.BuildResult.IsGenerateSuccess)
                |> List.map
                    (fun report -> report.BuildResult.ErrorMessage)
            
            failwith ""

@nojaf
Copy link
Contributor

nojaf commented Apr 27, 2021

Hey @Smaug123, I believe this is solved now. Could you confirm, please?

@nojaf
Copy link
Contributor

nojaf commented May 8, 2021

Closing as original internal report cannot be verified.

@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