Skip to content

newlines.beforeOpenParenDefnSite = unfold unnecessarily wraps extension clause in the presence of a doc comment #3497

@djneades

Description

@djneades

Configuration (required)

.scalafmt.conf:

version = "3.7.2"
maxColumn = 80

runner.dialect = scala3

newlines {
   beforeOpenParenDefnSite = unfold
}

Command-line parameters (required)

When I run scalafmt via CLI like this: scalafmt test.scala

Steps

Given code like this:

extension (s: String)

  /** ... */
  def foo(): Unit = ???
  def bar(): Unit = ???

Problem

Scalafmt formats code like this:

extension
  (s: String)

  /** ... */
  def foo(): Unit = ???
  def bar(): Unit = ???

Expectation

I should like the formatted output to look like this:

extension (s: String)

  /** ... */
  def foo(): Unit = ???
  def bar(): Unit = ???

Workaround

n/a

Notes

Since extension (s: String) easily fits on a single line, it should not be wrapped on to two lines even with newlines.beforeOpenParenDefnSite = unfold.

If the doc comment /** ... */ is removed from before the def foo(), the formatting works as expected (except that there is no space after the extension keyword, but that may be configurable).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions