scala-collection-compat icon indicating copy to clipboard operation
scala-collection-compat copied to clipboard

scalafix can't find 'RoughlyMapValues'

Open natansil opened this issue 3 years ago • 9 comments

scalafix dependency:[email protected]:scala-collection-migrations:2.6.0 [error] (Compile / scalafix) scalafix.sbt.InvalidArgument: Unknown rule 'RoughlyMapValues'

This is how I setup my sbt.build file

natansil avatar Jan 31 '22 18:01 natansil

@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...?

SethTisue avatar Feb 12 '22 17:02 SethTisue

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

sjrd avatar Feb 12 '22 23:02 sjrd

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:[email protected]:scala-collection-migrations:2.6.0

Tell me if you need more help!

mlachkar avatar Feb 14 '22 10:02 mlachkar

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.

natansil avatar Feb 16 '22 09:02 natansil

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

SethTisue avatar Feb 16 '22 15:02 SethTisue

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?

natansil avatar Feb 16 '22 16:02 natansil

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

SethTisue avatar Oct 28 '22 14:10 SethTisue

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

olegbonar avatar Jun 06 '23 15:06 olegbonar

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

SethTisue avatar Jun 15 '23 22:06 SethTisue