Skip to content

Consider wider default format for record declarations if any XML doc comments are present on fields #1879

Closed
@dsyme

Description

From dotnet/docs#25972 (comment)

I propose we use wide formatting of records type declarations in implementation or signature file when any of the fields of the record type have XML comments.

Proposal

The proposal is to have

  • record type definitions without XML doc be formatted compactly (record definition braces on same column = false)
  • record type definitions with XML doc be formatted widely (record definition braces on same column = true).

This is roughly what was implemented for signature file generation in dotnet/fsharp#12072.

So default formats are as today if no XML doc:

type PostalAddress =
    { Address: string
      City: string
      Zip: string }

and wide if XML doc:

type PostalAddress =
    {
      /// The address
      Address: string

      /// The city
      City: string

      /// The zip code
      Zip: string
    }

I'd also propose that wide format be used even if only one member is XML doc commented:

type PostalAddress =
    {
      Address: string
      City: string

      /// The zip code
      Zip: string
    }

###' Background

Fantomas defaults to compact format for records

// Declaring additional members on PostalAddress
type PostalAddress =
    { Address: string
      City: string
      Zip: string }

This seems a good default. However, as soon as XML doc comments are added it sufers. That is, if we follow the style guide rule that the /// has a blank line before it, except the first, we get this:

// Declaring additional members on PostalAddress
type PostalAddress =
    { /// The address
      Address: string

      /// The city
      City: string

      /// The zip code
      Zip: string }

The only setting available to adjust this is the very widely affecting fsharp_multiline_block_brackets_on_same_column. However that would be too broadly applicable - record type definitions are the only place in the syntax where XML doc comments interact with block brackets.

Pros and cons

The main disadvantage is that this is a discontinuous approach that people may find confusing.

The main advantage is that it supports the principal that the "destination" of code be XML-doc commented.

Alternatives

Make wide formatting the default for all record expressions.

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