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)

Albert Meltzer
@kitbellew
@olafurpg how can i ask coursier to pull in the additional jar into the bootstrap for base scalafix?
and say i did add it, or packaged the external rule into a separate jar and listed it via --tool-classpath; how do i get scalafix to invoke it? all examples are by adding a dependency in sbt via rule@x:y:z but this approach is different
ah, and the build tool is maven
Ólafur Páll Geirsson
@olafurpg
@kitbellew have you tried this plugin? https://github.com/evis/scalafix-maven-plugin
You can add multiple dependencies to the same coursier bootstrap command. You may need to specify the main class
Once the external rule is available on the same classpath as scalafix-cli (or tool classpath) then you can reference the rule via name
Ólafur Páll Geirsson
@olafurpg
The rule@ syntax is an sbt-only feature, which is prinarily intended for one-off refactorings
Albert Meltzer
@kitbellew
@olafurpg thanks, tried the plugin. will need a fix because it currently supports only one version of scala. evis/scalafix-maven-plugin#12
Krzysiek Bochenek
@kpbochenek
Hi, I want to forbid certain implicit(import?) from using in my codebase and I was wondering is it something scalafix can do? Is there a rule that potentially could be used? Or maybe there is better dedicated tool for that?
Tomasz Godzik
@tgodzik
@kpbochenek I think it should be possible, but you would need to write a custom linting rule.
Krzysiek Bochenek
@kpbochenek
@tgodzik nice! do you have any examples where I could start looking at this? are there any custom linting rules already doing something similar?
Tomasz Godzik
@tgodzik
@kpbochenek here should be some, but I have some ideas how this should work
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