Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 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
  • Aug 15 20:32
    bjaglin opened #1657
  • Aug 14 20:55
    scala-steward opened #1656
  • Aug 14 15:30

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • Aug 14 15:27

    bjaglin on main

    Fix small issues with the docs Merge pull request #1654 from s… (compare)

  • Aug 14 15:27
    bjaglin closed #1654
  • Aug 14 15:20
    bjaglin edited #1655
  • Aug 14 15:16
    bjaglin opened #1655
  • Aug 14 15:16

    bjaglin on gitter2discord

    remote gitter shield (compare)

  • Aug 14 15:01

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • Aug 14 14:58

    bjaglin on main

    Use scalameta's Discord rather … Merge pull request #1653 from b… (compare)

  • Aug 14 14:58
    bjaglin closed #1653
  • Aug 14 11:57
    ssanj opened #1654
  • Aug 12 15:21
    rvacaru synchronize #1650
vttran
@vttranlina
Hello, I'm new.
I trying https://github.com/evis/scalafix-maven-plugin. I got an error
error: The ExplicitResultTypes rule needs to run with the same Scala binary version as the one used to compile target sources (2.13). To fix this problem, either remove ExplicitResultTypes from .scalafix.conf or make sure the scalafixScalaBinaryVersion setting key matches 2.13., But I'm using scala 2.13.4. I tried to upgrade to 2.13.6, even downgrade to 2.13.0, but it still not working.
Does anybody get same error?
3 replies
Gábor Bakos
@aborg0
Hello,
Thanks for the framework and tools. :) I made two rules and I am curious whether you would be interested to distribute (any of) them as part of scalafix. In case yes, I can try to prepare PRs in the coming weeks.
The first rule checks whether the case class argument names match the variables in the pattern match (but only if the case class extends a marker trait).
The other rule is slick specific, but probably with other effect types there might be similar issues. With code blocks we can have multiple DBIOActions, but only the last one is returned, others are ignored. This fix wraps them with DBIO.seq.
You can find them here: https://github.com/aborg0/customfixes (There are probably edge cases not covered.)
2 replies
foldl
@sagifogel
Hi,
How can I disable the plugin only for Scala3 when I have crossScalaVersions of 2.x and 3.x?
Thanks.
17 replies
Meriam Lachkar
@mlachkar

@/all

New release of Scalafix 0.9.30

We are happy to announce the release of Scalafix 0.9.30. Huge thanks to @taisukeoe and @adpi2 for their great contributions (release notes: 1 and , 2).

Release highlights:

  • New feature added to RemoveUnused rule that allows removing unused function parameters (scalacenter/scalafix#1444, scalacenter/scalafix#1448)
  • The support for sbt 0.13 is now dropped, which means that starting this version, the plugin is only available for sbt 1.x. It's still possible to use the latest scalafix version with an older scalafix plugin by overriding the scalafix-interfaces dependency as described in the documentation.
  • Some rules rely on the warning messages to apply some fixes. Since 2.12.13 and 2.13.x, the number of warnings stored by scalameta depended on a compiler option -Xmaxwarns, which limits the number of fixes applied during each run, and the user had to configure this scalacOption to catch more warnings. Starting this release, this configuration is not necessary anymore. The rule will fix all the warnings, even if there are not printed by the compiler.
Brice Jaglin
@bjaglin
Scalafix 0.9.31 was just cut with support for Scala 2.12.15 (thanks @tgodzik for the fast turnaound on scalameta as usual) & the possibility to lookup overriddenSymbols (thanks @tanishiking)
https://github.com/scalacenter/scalafix/releases/tag/v0.9.31
https://github.com/scalacenter/sbt-scalafix/releases/tag/v0.9.31
1 reply
Boris Smidt
@borissmidt

I'm trying to replace a method which changes form 1 bracket to 2 bracketed method.
So i expted that i could do, but this will result in code that will rewrite the full chain again.

val t : Term.Apply //these are the flatmap applies gotten in a collect
Patch.replaceTree(t, Term.Apply(t.copy(fun.copy(name = Term.Name("mapParallelUnordered")), List(args.head)), List(args.last)).toString())

input:

Observable(1,2,4)
  .flatMap(3, x => Observable.from(x))
  .flatMap(3, x => Observable.from(x))

expected output:

Observable(1,2,4)
  .mapParallelUnordered(3)(x => Observable.from(x))
  .mapParallelUnordered(3)(x => Observable.from(x))

If i would only like to do the rename this works:

val t : Term.Apply
Patch.replaceTree(fun.name, "mapParallelUnordered")

But a seemingly equivalent patch gives will also give repeat the full chain on each replacement:

val t : Term.Apply
Patch.replaceTree(t, t.copy(fun.copy(name = "mapParallelUnordered").toString)

so how do i rename one function to a different one which has 2 apply lists instead of 1.

1 reply
Ó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.