Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 18 19:16
    rvacaru synchronize #1650
  • Aug 18 18:06
    rvacaru synchronize #1650
  • Aug 18 17:52
    scala-steward opened #1659
  • Aug 18 09:41
    rvacaru synchronize #1650
  • Aug 18 09:41
    rvacaru synchronize #1650
  • Aug 18 09:11
    rvacaru synchronize #1650
  • Aug 18 00:00
    ssahayam-zd commented #1658
  • Aug 17 21:54
    bjaglin commented #1658
  • Aug 17 21:54
    bjaglin commented #1658
  • Aug 17 21:39
    bjaglin edited #1658
  • Aug 17 11:02
    ssanj commented #1658
  • Aug 16 12:08
    bjaglin edited #1658
  • Aug 16 12:08
    bjaglin opened #1658
  • Aug 15 20:38

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • Aug 15 20:38

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • Aug 15 20:35

    bjaglin on main

    remote gitter shield Merge pull request #1655 from s… (compare)

  • Aug 15 20:35
    bjaglin closed #1655
  • Aug 15 20:35
    bjaglin ready_for_review #1655
  • Aug 15 20:35

    bjaglin on main

    Update scalafmt-core to 3.5.9 Merge pull request #1656 from s… (compare)

  • Aug 15 20:35
    bjaglin closed #1656
Ólafur Páll Geirsson
@olafurpg
@borissmidt have you tried replacing the comma token with parentheses?
3 replies
you want to avoid replaceTree against large trees since thats destructive for trivia like formatting details and comments
Ben Plommer
@bplommer
I'm trying to use sbt-scalafix to run scalafix rules defined in the same project, and it only works for scala 2.12 - in 2.13 I get scalafix.sbt.InvalidArgument: scalafix.v1.Rule: Provider fix.MyFix could not be instantiated. Is this to do with sbt being scala 2.12 only?
1 reply
Mark Dixon
@mnd999:matrix.org
[m]
I'm using the maven plugin (io.github.evis) and trying to run some of the rules from the scala-rewrites package. Unfortunately, I keep getting errors with the namespacing: error: {"rules": ["Collection213Upgrade", "Collection213Experimental", "fix.scala213.ScalaSeq", "fix.scala213.Core"]} has no field 'fix'.. Am I doing something wrong?
1 reply
Mark Dixon
@mnd999:matrix.org
[m]
Then is works, but does not run those rules
Ólafur Páll Geirsson
@olafurpg
Where are those rules coming from?
you maybe need to prefix “class:”
Which I have pulled in as a dependency of the maven plugin as I have for the Collection213 rules which are a different jar
Mark Dixon
@mnd999:matrix.org
[m]
I also tried "class:fix.scala213.ScalaSeq" and class:"fix.scala213.ScalaSeq" without success. The former gives the same error as above and the latter seems syntacticlly wrong.
Brice Jaglin
@bjaglin
@mnd999:matrix.org do you manage to run built-in rules? how does your .scalafix.conf look like?
Mark Dixon
@mnd999:matrix.org
[m]
It's as above, just those 4 rules. I'm able to run the first to which do not have any dotted prefix, it's just the ones starting fix. that seem to cause issues. Surely this is something simple I'm doing wrong?
Mark Dixon
@mnd999:matrix.org
[m]
Okay I got it, it's not the rules config, that rule requires additional config, or it just crashes. You have to add additional config fix.scala213.ScalaSeq {} or it will die with that fix. error which is super confusing.

quit

\quit
Ólafur Páll Geirsson
@olafurpg
@mnd999:matrix.org can you send a PR to the upstream repo to document that requirement?
stoco-loco
@luca-battistelli

Hello everyone, I'm using a custom dependency loaded on some custom resolvers. When I add them as

ThisBuild / scalafixDependencies += "com.foo.bar"  %% "scalafix-foo" % "1.0.0"
ThisBuild / scalafixResolvers ++=  ...

lazy val myProject = project
  .settings(
    // ...
  )

everything works fine. If I inspect my build with consoleProject I can see my scalafixDependencies and scalafixResolvers in ThisBuild and in myProject.

However if I move the scalafix settings in the project like so:

lazy val myProject = project
  .settings(
    // ...
    scalafixDependencies += "com.foo.bar"  %% "scalafix-foo" % "1.0.0",
    scalafixResolvers ++=  ...
  )

scalafixAll gives me a [error] (scalafixAll) scalafix.sbt.InvalidArgument: Unknown rule 'MyRule'. If I inspect my build with consoleProject I can see my scalafixDependencies and scalafixResolvers in myProject but not in ThisBuild.

Can anyone help? I need to move the settings inside the project as in my company we're using using a custom sbt plugin that creates project with standard settings.

2 replies
Brice Jaglin
@bjaglin
@/all scalafix 0.9.32 is out with support for scala 2.13.7 & a bugfix for overriddenSymbols (scalacenter/scalafix#1476). Thanks @tanishiking & @SethTisue for the contributions!
Mark Dixon
@mnd999:matrix.org
[m]
Hi, Does scalafix support Java 17? I'm trying to run some rules to upgrade Scala 2.12 code to 2.13 and I'm getting Unsupported class file major version 61
Meriam Lachkar
@mlachkar
Hello! In fact Scalafix will fail in java 17, but the error you are having is during the compilation (not a Scalafix error). Do you run scalafix on scala 2.12 or 2.13 ?
In all cases to use java 17, you need to have the latest version of scala 2.12 or 2.13 because the support of java 17 have been added only recently.
So migrate first to the lastest version of 2.12, and make sure it compiles fine with Java 17.
For scalafix, I will release a new version today for java 17 support!
Meriam Lachkar
@mlachkar
@/all scalafix 0.9.33 is out. It fixes the support for jdk17 and it fixes an issue on ExplicitResultTypes. Thanks for your contributions!
Mark Dixon
@mnd999:matrix.org
[m]
@mlachkar-5d094c08d73408ce4fc3e2dc it's certainly not a compliation issue, nor does it work in v0.9.33. I created a github issue scalacenter/scalafix#1503
1 reply
Bill Frasure
@swoogles

Hi all, I've got a rule defined that has been successfully applied to multiple projects already, but there are some projects that throw this error when I execute it:

[error] [E0] /tmp/scalafix2610516103563897436/Zio2Upgrade.scala3899217760876070558.scala:450:13 error: wrong number of type parameters for method map: [B, That](f: scalafix.v1.SymbolMatcher => B)(implicit bf: scala.collection.generic.CanBuildFrom[List[scalafix.v1.SymbolMatcher],B,That])That
[error]         }.map[PartialFunction[Tree, Patch]](symbolMatcher => { case t @ ImporteeNameOrRename(symbolMatcher(tree)) =>

The rule is here: https://github.com/zio/zio/blob/series/2.x/scalafix/rules/src/main/scala/fix/Zio2Upgrade.scala
The project we're applying it to is here: https://github.com/zio/zio-akka-cluster

5 replies
Marcelo
@marcelocenerine
Hi all :wave: . We've recently received a request to introduce support for Scala 3 in the Scalafix plugin for Gradle (cosmicsilence/gradle-scalafix#60). I read the announcement and it seems that support for Scala 3 is already available in Scalafix as experimental. However, looking at scalafix.interfaces.Scalafix (latest) it's not clear what is required to uptake that. I would appreciate if you could provide some pointers on how we could provide equivalent functionality as the plugin for sbt (if any), or maybe just let us know if this is still very early days and we should hold that off for now.
Ólafur Páll Geirsson
@olafurpg
@marcelocenerine I left a comment on the gradle-scalafix issue
Marcelo
@marcelocenerine
Awesome. Thanks @olafurpg
James Reddick
@reddicj
Hi I have a tiny test project to test the Scala 2.13 Collection migration rules (https://github.com/reddicj/scalafix-212). When I run scalafix Collection213Upgrade the HelloWorld.scala file doesn't get rewritten with any fixes?? I can't figure out what is wrong. Any help appreciated..
Jack Koenig
@jackkoenig
I feel like I'm missing something, but how do I create a Patch to replace a Defn.Val with a Defn.Class and a Defn.Val? I'm able to create the correct Class and Val but how do I turn those into a Patch? The Patch API seems to just want Strings
Jack Koenig
@jackkoenig
Patch.replaceTree(originalVal, newClass.toString + newVal.toString) works but with terrible formatting (scalafmt can save me), but I still feel like there's got to be a better way
Jack Koenig
@jackkoenig
Ah this approach deletes all of the comments, that's not ideal... Guess I'll have to find a way to make the Patches a little more focused
Ólafur Páll Geirsson
@olafurpg
@jackkoenig Patch works best with tokens, not trees
Think of Patch as the steps you would perform in an editor with the minimum number of removals
Jack Koenig
@jackkoenig
@olafurpg that makes a lot of sense, thanks for correcting my mental model! It does make a lot more sense as edits vs. injecting trees (since those necessarily wouldn't maintain formatting and comments). Happy new year and thanks for the great tool!
Jack Koenig
@jackkoenig
How might one create a patch that is supposed to replace anonymous classes instances with named classes? eg.
val foo = new Whatever {
  ...
}
// rewrite to
val foo = new Impl
class Impl extends Whatever {
  ...
}
I can identify everything I need and as noted above, I can do it with trees, but I don't see what sort of patches I can do to a Term.NewAnonymous(tmpl) when need to turn that tmpl into a class
Jack Koenig
@jackkoenig

Okay figured it out, you can delete the new by accessing the tokens of the Term.NewAnonymous directly and removing the first one, ie. the solution here is:

val newAnon = ... // bound to the Term.NewAnonymous via matching
Patch.removeTokens(newAnon.tokens.head) +
  Patch.addLeft(newAnon, "new Impl\n  class Impl extends")

I gotta say, much happier with this than the sed script I was contemplating :)

Jack Koenig
@jackkoenig
Is it possible (or better yet, does such code exist) to write a scalafix rewriter to hoist certain inner classes? The main issue here is figuring out what arguments that were captured automatically need to be made explicit
1 reply
Brice Jaglin
@bjaglin
scalafix & sbt-scalafix 0.9.34 are out with support for scala 2.13.8 (tagged but not announced yet, see https://github.com/scala/scala-dev/issues/802#issuecomment-1009390321), thanks @tgodzik!
Jason Pickens
@steinybot
I’ve been thinking about a tool that would help minimise code to create minimal reproductions for bug reports. I’m wondering if I could do it with scalafix or if I should use scalameta directly.
AFAIK scalafix rules only operate on a single document but I would probably need information for the entire project
I was hoping I could use Patch but the implementations are all internal and there isn’t much that can be done with Patch directly.
Brice Jaglin
@bjaglin
@steinybot I think scalafix will get in the way more than helping you if your goal is to cut off/bisect syntax trees - I would POC something against scalameta indeed
(that sounds like an amazing tool!)
Jason Pickens
@steinybot
I suspected that would probably be the case. I haven’t figured out exactly how it should work yet.
Ólafur Páll Geirsson
@olafurpg
@steinybot there’s maybe some prior art here https://stryker-mutator.io/docs/stryker4s/getting-started/
Natan Silnitsky
@natansil

Hi,
Kinda late to the 2.13 party
I'm getting the following error when running scalafix dependency:RoughlyMapValues@org.scala-lang.modules:scala-collection-compat:2.6.0 in order to fix the mapValues MapView errors:
[error] (Compile / scalafix) scalafix.sbt.InvalidArgument: Unknown rule 'RoughlyMapValues'

I've added ThisBuild / scalafixDependencies += "org.scala-lang.modules" %% "scala-collection-migrations" % "2.6.0" to build.sbt
I've also added addCompilerPlugin(scalafixSemanticdb), scalacOptions ++= List("-Yrangepos", "-P:semanticdb:synthetics:on"),

Is this error expected? what am I missing?

Ólafur Páll Geirsson
@olafurpg
@natansil what happens if you run “scalafix RoughlyMapValues”?
the “dependency:” syntax is only needed if you dont configure scalafixDependencies
Should it be “scala-collection-migrations” instead of “-compat”?
Natan Silnitsky
@natansil
@olafurpg both of your suggestions fail (while Collection213Upgrade doesn't fail)
scalafix dependency:RoughlyMapValues@org.scala-lang.modules:scala-collection-migrations:2.6.0
[error] (Compile / scalafix) scalafix.sbt.InvalidArgument: Unknown rule 'RoughlyMapValues'
scalafix RoughlyMapValues
[error] (Compile / scalafix) scalafix.sbt.InvalidArgument: Unknown rule 'RoughlyMapValues'
scalafix Collection213Upgrade
[info] compiling 69 Scala sources...