scalacenter / scalafix

Refactoring and linting tool for Scala
https://scalacenter.github.io/scalafix/
BSD 3-Clause "New" or "Revised" License
831 stars 186 forks source link

RemoveUnused: Expression parentheses not properly handled after removing unused variable #2061

Open nox213 opened 2 months ago

nox213 commented 2 months ago

Removing an unused variable with Scalafix’s RemoveUnused rule leaves unbalanced parentheses in expressions, resulting in invalid syntax.

scala version: 2.13.13 sbt version: 1.10.1 scalafix version: 0.12.1

build.sbt

ThisBuild / scalaVersion := "2.13.13"
ThisBuild / semanticdbEnabled := true
ThisBuild / semanticdbVersion := scalafixSemanticdb.revision

lazy val root = (project in file("."))
  .settings(
    name := "Test",
    scalacOptions += {
      "-Wunused:locals"
    }
  )

Before

object Main {
  def main(args: Array[String]): Unit = {
    val a: Int =
      (3
        + 4)
  }
}

After

object Main {
  def main(args: Array[String]): Unit = {
    3
        + 4)
  }
}
bjaglin commented 2 months ago

Thanks for the great bug report! I'll try to look at it in the coming days.