Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 05 18:14
    bjaglin edited #1683
  • Oct 05 18:14
    bjaglin edited #1683
  • Oct 05 18:13
    bjaglin synchronize #1683
  • Oct 05 18:13

    bjaglin on scalameta460

    mdoc 2.3.6 scalameta 4.6.0 (compare)

  • Oct 04 08:51
    tgodzik commented #1683
  • Oct 03 14:48
    tgodzik commented #1683
  • Oct 02 23:31
    bjaglin edited #1683
  • Oct 02 23:30
    bjaglin edited #1683
  • Oct 02 21:50
    bjaglin edited #1658
  • Oct 02 21:50
    bjaglin edited #1658
  • Oct 02 21:49
    bjaglin edited #1658
  • Oct 02 21:46
    bjaglin edited #1680
  • Oct 02 21:46
    bjaglin edited #1680
  • Oct 02 21:45
    bjaglin edited #1680
  • Oct 02 21:36
    bjaglin commented #1683
  • Oct 02 21:23
    bjaglin commented #951
  • Oct 02 21:10
    bjaglin edited #1683
  • Oct 02 21:06
    bjaglin opened #1683
  • Oct 02 21:06

    bjaglin on scalameta460

    scalameta 4.6.0 (compare)

  • Oct 02 21:00
    bjaglin edited #1650
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
Brice Jaglin
@bjaglin

@earldouglas:matrix.org another possibility is to inject CLI args programmatically

Either by redefining scalafix/scalafixAll

Compile / scalafix := (Compile /scalafix).partialInput(" --settings.DisableSyntax.noSemicolons DisableSyntax").evaluated // also needed for Test
scalafixAll := scalafixAll.partialInput(" --settings.DisableSyntax.noSemicolons DisableSyntax").evaluated

or by declaring a new task using the built-in input keys (safer and less confusing for the end-user....)

lazy val lint = taskKey[Unit]("")
lint := scalafixAll.toTask(" --settings.DisableSyntax.noSemicolons DisableSyntax").value
earldouglas
@earldouglas:matrix.org
[m]
@olafurpg: Thanks, that's what I'm currently doing. It works, but it feels like there could be a better way.
@bjaglin: Ah ha, that looks like what I need. Thanks!
earldouglas
@earldouglas:matrix.org
[m]
:point_up: Edit: @bjaglin: Thanks, that looks like what I need. Is there a way to have the redefined compile use this, since I'm using scalafixOnCompile? Or could I re-redefine compile to do so?
Brice Jaglin
@bjaglin
@earldouglas:matrix.org scalafix is evaluated by compilewhen scalafixOnCompile is set (https://github.com/scalacenter/sbt-scalafix/blob/0a4dfc6a32d67b701235876fe5658f04c9c9687a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala#L108-L116), so redefining scalafix like suggested in the first option should do the trick.
earldouglas
@earldouglas:matrix.org
[m]
That worked; thanks!
Brice Jaglin
@bjaglin

@/all Thanks to all our contributors, Scalafix 0.10.0-RC1 is out with the following highlights:

  • Breaking changes for rule authors (see release notes)
  • Compatibility checks when loading external rules
  • Deprecated keys & dependency to coursier-small removed from ScalafixPlugin
  • sbt-scalafix now only supports sbt 1.3+
  • scalafixEnable no longer overrides projects' scalaVersion unless really necessary
  • A new logo, visible in the docs -> https://scalacenter.github.io/scalafix/

More details on the full release notes:

Your user/rule author feedback is welcome on this release candidate.
If no major issue or obstacle is found in RC1, a final release will be cut on April 7th.