Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 23 00:14
    bjaglin synchronize #1650
  • Sep 23 00:05
    bjaglin commented #1650
  • Sep 23 00:04
    bjaglin synchronize #1650
  • Sep 22 23:27
    bjaglin synchronize #1650
  • Sep 22 21:37
    bjaglin synchronize #1650
  • Sep 22 21:35
    bjaglin synchronize #1650
  • Sep 22 21:29
    bjaglin synchronize #1650
  • Sep 22 21:05
    bjaglin synchronize #1650
  • Sep 20 23:55

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • Sep 20 23:52

    bjaglin on main

    Post 0.10.3 release Merge pull request #1679 from s… (compare)

  • Sep 20 23:52
    bjaglin closed #1679
  • Sep 20 23:52
    bjaglin ready_for_review #1679
  • Sep 20 23:51
    bjaglin commented #1631
  • Sep 20 23:51
    bjaglin closed #1675
  • Sep 20 23:51
    bjaglin commented #1675
  • Sep 20 23:39
    bjaglin synchronize #1679
  • Sep 20 23:39

    bjaglin on post0103

    Post 0.10.3 release (compare)

  • Sep 20 23:30

    bjaglin on v0.10.3

    (compare)

  • Sep 20 23:28

    bjaglin on v0.10.3

    (compare)

  • Sep 20 22:36

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

Mark Dixon
@mnd999:matrix.org
[m]
\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...
Ólafur Páll Geirsson
@olafurpg
Im not familiar with the RoughlyMapValues rule, have you reported an issue to that repo?
If Collection213Upgrade ia working successfully then it sounds like everything is OK on your side
Natan Silnitsky
@natansil
Cool. Thanks! I will report the issue then...
Brice Jaglin
@bjaglin
Oliver Schrenk
@oschrenk
I have a project still running sbt 1.4.9. Is there a scalafix rule to (help me) migrate to sbt 1.5.7?
Oliver Schrenk
@oschrenk

At https://eed3si9n.com/sbt-1.5.0 I found

scalafix --rules=https://gist.githubusercontent.com/eed3si9n/57e83f5330592d968ce49f0d5030d4d5/raw/7f576f16a90e432baa49911c9a66204c354947bb/Sbt0_13BuildSyntax.scala *.sbt project/*.scala

But it fails with

 scalafix.sbt.InvalidArgument: 2 errors
Oliver Schrenk
@oschrenk

Oh. That page doesn't mention to install scalfix via coursier. It's only mentioned at syntactic Scalafix rule for unified slash syntax

Curious why the same command works then but not from within sbt.

Ólafur Páll Geirsson
@olafurpg
@oschrenk the sbt plugin has its own cli parser to integrate natively with sbt (for example, allow tab completions). The sbt plugin also has a different execution model, an unscoped “scalafix” command in the sbt shell runs scalatix independently for every project in the build (with the liat of sources and classpath configured per project/config pair) while the cli runs once against the recursive list of scala files
Also, the sbt shell doesn’t do glob expansion
earldouglas
@earldouglas:matrix.org
[m]
Is there a way to set the Scalafix configuration directly via an sbt setting, rather than through an external .scalafix.conf file?
I'm writing an sbt plugin that uses a Scalafix rule, and I don't want users to need to add a .scalafix.conf file.
Ólafur Páll Geirsson
@olafurpg
@earldouglas:matrix.org one workaround is to generate a .scalafix.conf file from the sbt plugin
You can configure sbt-scalafix to read the config from a custom file, which can live under target/ so that users don't see it