scala / scala-collection-compat

makes some Scala 2.13 APIs (primarily collections, also some others) available on 2.11 and 2.12, to aid cross-building
Apache License 2.0
203 stars 87 forks source link

scalafix can't find 'RoughlyMapValues' #517

Open natansil opened 2 years ago

natansil commented 2 years ago

scalafix dependency:RoughlyMapValues@org.scala-lang.modules:scala-collection-migrations:2.6.0 [error] (Compile / scalafix) scalafix.sbt.InvalidArgument: Unknown rule 'RoughlyMapValues'

This is how I setup my sbt.build file

SethTisue commented 2 years ago

@sjrd the scalafix rules in this repo were developed at the Center; is there someone there who would like to take a look at this...?

sjrd commented 2 years ago

@mlachkar Are you familiar with the above rule and/or why it is not found?

mlachkar commented 2 years ago

The rules provided by scala-collection-compat are the following:

Collection213CrossCompat
Collection213Upgrade
Collection213Experimental
Collection213Roughly

So there is no rule called RoughlyMapValues. I guess its name is Collection213Roughly.

The easiest way to run those rules is to add scalafix in your plugin list

// plugins.sbt
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.33")

then add the dependency to this rule in your build:

// build.sbt
ThisBuild / scalafixDependencies += "org.scala-lang.modules" %% "scala-collection-migrations" % "2.6.0"

And then add them to the configuration of scalafix: .scalafix.conf

rules = [
Collection213CrossCompat,
Collection213Upgrade,
Collection213Experimental,
Collection213Roughly
]

And then launch sbt shell, and run scalafixAll After doing so, you can remove the rules, since it's only needed for one run only!

You can also run with scalafix command through sbt shell

scalafixAll dependency:Collection213Roughly@org.scala-lang.modules:scala-collection-migrations:2.6.0

Tell me if you need more help!

natansil commented 2 years ago

Hi @mlachkar, Thank you so much for answering in a detailed manner. The documentation states that there is a rule called RoughlyMapValues for the specific breaking change of mapValues returning a MapView instead of Map

I've tried running scalafix with Collection213Roughly (doc states that it fixes "Stream is replaced with LazyList"), it runs successfully, but it doesn't fix any of the mapValues lines of code.

SethTisue commented 2 years ago

relevant: https://github.com/scala/scala-collection-compat/pull/107

natansil commented 2 years ago

can it be that https://github.com/scala/scala-collection-compat/blob/main/scalafix/rules/src/main/scala/scala/fix/collection/Collection213Roughly.scala just doesn't work?

SethTisue commented 2 years ago

Sounds plausible — do we have any test coverage for it?

olegbonar commented 1 year ago

This one took me a while to solve. I guess the documentation is quite misleading: there is no such rule as RoughlyMapValues, it's named Collection213Roughly instead. In order to run it one should provide explicit configuration via .scalafix.conf for example:

Collection213Roughly.strictMapValues = true
Collection213Roughly.strictFilterKeys = true

By default all the fixes are disabled somehow

SethTisue commented 1 year ago

@olegbonar Thank you for looking into it! Would you be interested in submitting a PR that improves the documentation...?