fsharp / fslang-design

RFCs and docs related to the F# language design process, see https://github.com/fsharp/fslang-suggestions to submit ideas
518 stars 144 forks source link

[style-guide] Multiline base constructor call #693

Closed nojaf closed 1 year ago

nojaf commented 2 years ago

How would the style guide envision the following inherit function calls are formatted?

type UnhandledWebException =
    inherit Exception

    new(status: WebExceptionStatus, innerException: Exception) =
        { inherit Exception(SPrintF1
                                "Backend not prepared for this WebException with Status[%i]"
                                (int status),
                            innerException) }

    new(info: SerializationInfo, context: StreamingContext) =
        { inherit Exception(info, context) }

type FieldNotFoundException<'T>(obj: 'T, field: string, specLink: string) =
    inherit SwaggerSchemaParseException(sprintf
                                            "Object MUST contain field `%s` (See %s for more details).\nObject:%A"
                                            field
                                            specLink
                                            obj)

Should the expressions after the inherit follow the same rules as https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting#formatting-application-expressions?

Something like

type UnhandledWebException =
    inherit Exception

    new(status: WebExceptionStatus, innerException: Exception) =
        { inherit
            Exception(
                SPrintF1 "Backend not prepared for this WebException with Status[%i]" (int status),
                innerException
            ) }

    new(info: SerializationInfo, context: StreamingContext) = { inherit Exception(info, context) }

type FieldNotFoundException<'T>(obj: 'T, field: string, specLink: string) =
    inherit 
        SwaggerSchemaParseException(
            sprintf
                "Object MUST contain field `%s` (See %s for more details).\nObject:%A"
                field
                specLink
                obj
        )

?

Adding the extra indent and new line after inherit would allow for the "indentation flow" to be preserved.

Thoughts?

dsyme commented 1 year ago

@nojaf Yes, that's ok. Approved

dsyme commented 1 year ago

Thank you for doing the doc updates @nojaf !