scalacenter / scalafix

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

RemoveUnused with -Ywarn-unused:<option> #1848

Open bmarker opened 1 year ago

bmarker commented 1 year ago

RemoveUnused and the removeUnused option for OrganizedImports don't seem to recognize the -Ywarn-unused:imports and similar options.

I had these from tpolecat:

  "-Ywarn-unused:implicits",           // Warn if an implicit parameter is unused.
  "-Ywarn-unused:imports",             // Warn if an import selector is not referenced.
  "-Ywarn-unused:locals",              // Warn if a local definition is unused.
  "-Ywarn-unused:params",              // Warn if a value parameter is unused.
  "-Ywarn-unused:patvars",             // Warn if a variable bound in a pattern is unused.
  "-Ywarn-unused:privates",            // Warn if a private member is unused.

But I still had to add -Ywarn-unused to get removing unused imports working.

I don't know if there's a check for the scalacOptions that could be adjusted or if it's more about how the rules work.

bmarker commented 1 year ago

It looks like it's looking for a prefix to me : https://github.com/scalacenter/scalafix/blob/691a4f013bf92410ae3d29a21058fafb41817044/scalafix-rules/src/main/scala/scalafix/internal/rule/RemoveUnused.scala#L32

I also don't get a warning that the option is not set. However, nothing gets auto-fixed either.

bmarker commented 1 year ago

I'm using -Xfatal-warnings and -Wconf:cat=unused:info. I wonder if it's the -Wconf that's specific to unused and not unused:imports.

bjaglin commented 3 weeks ago

I'm using -Xfatal-warnings and -Wconf:cat=unused:info. I wonder if it's the -Wconf that's specific to unused and not unused:imports.

Could you provide a repro?