Skip to content

Newline inconsistency in object expression #2990

Description

@MangelMaxime

Issue created from fantomas-online

Code

let helpers =
    { new IDecoderHelpers<JToken> with
        member _.isString jsonValue =
            not (isNull jsonValue) && jsonValue.Type = JTokenType.String
        member _.asFloat jsonValue = jsonValue.Value<float>()
        member _.asInt jsonValue = jsonValue.Value<int>()
        member _.getObjectKeys jsonValue =
            jsonValue.Value<JObject>().Properties()
            |> Seq.map (fun prop -> prop.Name)
        member _.getField(fieldName: string, jsonValue: JToken) = jsonValue[fieldName]

    }


let helpers2 =
    { new IDecoderHelpers<JToken> with
        member _.anyToString jsonValue =
            if isNull jsonValue then
                "null"
            else
                use stream = new StringWriter(NewLine = "\n")

                stream.ToString()
    }

Result

let helpers =
    { new IDecoderHelpers<JToken> with
        member _.isString jsonValue =
            not (isNull jsonValue) && jsonValue.Type = JTokenType.String

        member _.asFloat jsonValue = jsonValue.Value<float>()
        member _.asInt jsonValue = jsonValue.Value<int>()

        member _.getObjectKeys jsonValue =
            jsonValue.Value<JObject>().Properties() |> Seq.map (fun prop -> prop.Name)

        member _.getField(fieldName: string, jsonValue: JToken) = jsonValue[fieldName]

    }


let helpers2 =
    { new IDecoderHelpers<JToken> with
        member _.anyToString jsonValue =
            if isNull jsonValue then
                "null"
            else
                use stream = new StringWriter(NewLine = "\n")

                stream.ToString() }

Problem description

I believe it would be better if there was a new line between each member, this would make the code more consistent. I think that if all the member are single line then not having a new line is fine.

Also, the placement of the trailing } is not always placed on a new line. I don't know what triggers that because in my project, I have a similar code as the member _.anyToString jsonValue = method and the } is placed on a new line and indented under the leading {.

Extra information

  • The formatted result breaks my code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.
  • I would like a release if this problem is solved.

Options

Fantomas main branch at 1/1/1990

    { config with
                AlternativeLongMemberDefinitions = true
                MultiLineLambdaClosingNewline = true }

Did you know that you can ignore files when formatting by using a .fantomasignore file?
PS: It's unlikely that someone else will solve your specific issue, as it's something that you have a personal stake in.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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