scalameta / scalafmt

Code formatter for Scala
http://scalameta.org/scalafmt
Apache License 2.0
1.44k stars 277 forks source link

RedundantParens removes too much parens #3901

Closed sjoerdmulder closed 7 months ago

sjoerdmulder commented 7 months ago

Configuration (required)

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

version = 3.8.1
runner.dialect = scala3
rewrite.rules = [RedundantParens]

Command-line parameters (required)

When I run scalafmt via CLI like this: scalafmt

Steps

I know it's a bit weird code (in actual code the a: Any is a marker-trait so that the inner match gives match error when a new implementation is added.)

Currently the formatted doesn't compiled anymore with a '=>' expected but 'match' found. error

Given code like this:

    Seq.empty.collect {
      case a: Any if (a match {
        case b: Any => b
      }) => a
    }

Problem

Scalafmt formats code like this:

    Seq.empty.collect {
      case a: Any if a match {
            case b: Any => b
          } =>
        a
    }

Expectation

I would like the formatted output to look like this since the current formatted code by scalafmt

    Seq.empty.collect {
      case a: Any if (a match {
            case b: Any => b
          }) =>
        a
    }
kitbellew commented 7 months ago

@sjoerdmulder can you explain the problem you encounter? you have requested removal of redudant parens, and in scala3 (your chosen dialect), these parens are redundant.

sjoerdmulder commented 7 months ago

Ahhh sorry my bad! We are already using the scala3 formatting to prepare for scala3 migration but we still compile with scala2.13... so for scala 2.13 this is invalid code... using the Scala213Source3 as explained doesn't have the issue.