Skip to content

Idempotency problem with ifdef in a function #1646

Closed
@Smaug123

Description

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?

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions