Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removeOptionalBraces incorrectly deals with anonymous an class that calls a method #3537

Closed
jpsacha opened this issue May 1, 2023 · 0 comments · Fixed by #3538
Closed

removeOptionalBraces incorrectly deals with anonymous an class that calls a method #3537

jpsacha opened this issue May 1, 2023 · 0 comments · Fixed by #3538

Comments

@jpsacha
Copy link

jpsacha commented May 1, 2023

Configuration (required)

Please paste the contents of your .scalafmt.conf file here:

version = 3.7.3

runner.dialect = scala3
fileOverride {
  "glob:**/src/main/scala/**" {
    runner.dialect = scala3
  }
  "glob:**/src/main/scala-2/**" {
    runner.dialect = scala213source3
  }
  "glob:**/project/**.scala" {
    runner.dialect = scala213source3
  }
}

preset = IntelliJ
align.preset = more
maxColumn = 120
docstrings.style = Asterisk
docstrings.blankFirstLine = yes
docstrings.wrap = no
importSelectors = singleLine
newlines.source = keep

rewrite.scala3.convertToNewSyntax = yes
rewrite.scala3.removeOptionalBraces = yes
rewrite.scala3.insertEndMarkerMinLines = 42

Command-line parameters (required)

When I run scalafmt via CLI like this: scalafmt .\ScalaFMTBraceErrorDemo.scala

Steps

Given code like this:

class ScalaFMTBraceErrorDemo:

  class Foo(msg:String):
    def bar(): Unit =
      println(msg)

  new Foo("xyz") {
    print("msg")
  }.bar()

Problem

Scalafmt formats code like this:

class ScalaFMTBraceErrorDemo:

  class Foo(msg: String):
    def bar(): Unit =
      println(msg)

  new Foo("xyz"):
    print("msg")
    .bar()

This code does not compile anymore.

Expectation

I would like the formatted output to look like this:

class ScalaFMTBraceErrorDemo:

  class Foo(msg: String):
    def bar(): Unit =
      println(msg)

  new Foo("xyz"){
    print("msg")
  }.bar()

Workaround

Not known

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant