Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 22 11:30
    taisukeoe commented #1245
  • Jan 21 19:15
    mcanlas commented #1245
  • Jan 21 13:00
    bjaglin edited #1316
  • Jan 21 12:00
    bjaglin opened #1316
  • Jan 19 15:34
    mosesn commented #1305
  • Jan 17 22:09

    bjaglin on untagged-621a8517dbdd8b06c14f

    (compare)

  • Jan 16 12:12
    sideeffffect closed #1315
  • Jan 16 05:12
    rossabaker closed #1299
  • Jan 16 05:12
    rossabaker commented #1299
  • Jan 15 20:01
    sideeffffect edited #1315
  • Jan 15 19:59
    sideeffffect edited #1315
  • Jan 15 19:58
    sideeffffect opened #1315
  • Jan 15 18:07

    github-actions[bot] on untagged-621a8517dbdd8b06c14f

    (compare)

  • Jan 15 14:44

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • Jan 15 14:40

    mlachkar on v0.9.25

    (compare)

  • Jan 15 14:33

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • Jan 15 14:30

    tgodzik on master

    Update Scala versions to 2.13.4… Merge pull request #1314 from t… (compare)

  • Jan 15 14:30
    tgodzik closed #1314
  • Jan 15 14:16
    bjaglin edited #1314
  • Jan 15 14:05
    tgodzik synchronize #1314
Gavin Bisesi
@Daenyth

Does scalafix have an easy way to do something like this intellij lint: https://github.com/zio/zio-intellij/blob/idea202.x/src/main/scala/zio/intellij/inspections/mistakes/UnusedZIOExpressionsInspection.scala#L20

expr.nextSiblingNotWhitespace

I want to try to write a scalafix rule to detect misuse of cats-effect IO types (eg someIO; anotherIO)
I could probably fork/edit the zio-intellij stuff to get an intellij inspection warning, but I'd rather do it in scalafix so it works for all editors and can be easily checked in CI
Brice Jaglin
@bjaglin
Gavin Bisesi
@Daenyth
thanks
Gavin Bisesi
@Daenyth

Unrelated, I'd like to be able to detect usage of toString on specific types. I found this: https://github.com/mrdziuban/disable-to-string

but I'm wondering how easy it would be to check what toString is being invoked on, type-wise

an example might be Array[_]; you basically never want to toString that
Cheng Lian
@liancheng
Is there a good way to profile a Scalafix rule? For example, running a rule against a repository and generating a FlameGraph. I guess I can also just attach JProfiler/YJP to the sbt process while running the rule too, but would like to explorer whether there are any existing ways to produce profiling results automatically. More specifically, I was thinking about the performance of the OrganizeImports rule. Right now, it's written in a pretty plain FP style for clarity, but can be slow when executed against large repositories. Would like to see whether there're any low-hanging fruits there (e.g., rewriting certain hot for-loops into while-loops).
Ólafur Páll Geirsson
@olafurpg
@liancheng I normally use https://github.com/jvm-profiling-tools/async-profiler in cases like this.
It should be possible to setup JMH benchmarks for rules, requires a bit more ceremony but could give you better confidence that your optimizations actually have an effect
scalafix-testkit already configures the fixture to run a custom rule against an input file. You might be able to write a JMH benchmark that instantiates your test class and invokes a single test case.
Cheng Lian
@liancheng
Thank you, @olafurpg!
jahan01
@jahan01

Hello All,
How to make sbt-scalafix work with custom project directory structure in multi-module build. I am migrating this project from gradle to sbt only because gradle-scalafix doesn't organize imports correctly for few files

examples
├── file1.scala
├── file2.scala
src
├── main
│   └── scala
├── build.sbt

My build config looks like this:

lazy val core = project
  .in(file("."))
  .settings(
    name := "root-lib-project",
    libraryDependencies ++= Seq(...)
  )

lazy val examples = project
  .in(file("examples"))
  .settings(
    name := "lib-examples",
    Compile / scalaSource := baseDirectory.value,
    libraryDependencies ++= Seq(..)
  )
  .dependsOn(core)

The core/scalafix, scalafmt works fine without any issues and I am also able to compile the sources. Even organize-imports via metals is working correctly. But running examples/scalafix gives the below error.

[error] error while loading Object, Missing dependency 'object scala.native in compiler mirror', required by /modules/java.base/java/lang/Object.class
[error] ## Exception when compiling 2 sources to <proj_dir>/examples/target/scala-2.12/scalafix-classes
[error] scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
[error] scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:24)
[error] scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:25)
[error] scala.reflect.internal.Mirrors$RootsBase.$anonfun$getModuleOrClass$6(Mirrors.scala:65)
...
7 replies
Meriam Lachkar
@mlachkar
@all/ v0.9.24 is out, thanks to the contributors! We have mainly added the support for scala 2.13.4
https://github.com/scalacenter/scalafix/releases/tag/v0.9.24
https://github.com/scalacenter/sbt-scalafix/releases/tag/v0.9.24
felher
@felher

Hey folks.
I have a bunch of objects for which I want to guarantee that those objects are only accessed from a few specific packages of the code base. I'm looking for a way to basically do this:

object O {
  private[otherPackageA,otherPackageB] object Inner { }
}

Is this something that I could write a rule for, to check that during continuous integration? Seems like something scalafix could do, but before learning how write custom rules, I thought I'd better ask.

3 replies
Michael Thomas
@Michaelt293

I want to use Scalafix at work. We use gradle as our build tool and therefore want to use the gradle plug-in (https://github.com/cosmicsilence/gradle-scalafix). Unfortunately, when running Scalafix, the rules do not appear to be being applied. For example, I expect Scalafix to insert return types when applying the rule ExplicitResultTypes. I thought I may of set up the project incorrectly so I cloned the following project which uses gradle-Scalafix - https://github.com/Workday/warp-core/. I added the following code to a Scala file -

  def d = ""

  implicit class RichString(val string: String) {
    def scream = string.toUpperCase
   }

and ran the following command ./gradlew clean scalafix but still did not see any code changes. Any ideas on what might be the problem?

Michael Thomas
@Michaelt293
I think I figured it out. If the implicit class extends AnyVal, the private modifier is added (this is not mentioned in the documentation). Regarding ExplicitResultTypes, I believe literal values are ignored by default (this is mentioned in the documentation, my bad).
Yosef Fertel
@frosforever
Hey folks! Is it normal for scalafix RemoveUnused to possibly produce code that no longer compiles or have I run into an anomaly?
2 replies
Martijn
@martijnhoekstra:matrix.org
[m]
I'm trying to make a fix to rewrite Foo.bar(x) to x.baz and y.foo to y.bar. For the first, I'm using Patch.replaceTree on the Apply tree, and for the second, I'm using Patch.replaceTree on the Term.Name tree of foo. Now when I have Foo.bar(x.foo), it gets replaced with x.bar.bazbar instead of the expected x.bar.baz
what should I be doing differently? Am I using the right methods to select and replace trees and am I using them wrong, or am I using the wrong tools?
Brice Jaglin
@bjaglin
@martijnhoekstra:matrix.org That looks like a case of 2 patches targeting overlapping trees, which scalafix doesn't (can't?) handle well. If both patches are coming from the same rule, I would introduce a third that would handle the combination of both (and take precedence over the 2 others obviously). If not, I am afraid you will have to run the rules sequentially (2 different scalafix runs). There might be something smarter though!
Martijn
@martijnhoekstra:matrix.org
[m]
I'll see what I can make of it. Running 2 different runs are tricky to keep things compiling. It's a version upgrade that'll either compile with one version or the next
Ólafur Páll Geirsson
@olafurpg
@martijnhoekstra:matrix.org are you using “collect”?
You might be able to avoid duplicate patches with a vistom traverser
Martijn
@martijnhoekstra:matrix.org
[m]
Yes, I'm using collect. I'll give the custom traverse a go
Thanks for the pointer
Taisuke Oe
@taisukeoe
Hi.is there any way not to leave an empty line after Patch.removeTokens is applied?
Ólafur Páll Geirsson
@olafurpg
@taisukeoe have you tried to remove the trailing newline token?
Taisuke Oe
@taisukeoe
@olafurpg Not yet, and thank you for your suggestions! This one liner works.
(Patch.removeTokens(tree.tokens) + Patch.removeTokens(doc.tokenList.trailing(tree.tokens.last).takeWhile(t => t.is[Token.Space] || t.is[Token.LF] || t.is[Token.CR]))).atomic
Toby
@tobyweston
hi all, just wondering if anyone knows of a rule to help migrate away from scalaz, specifically, I'm after something to replace \/ with Either. Can't seem to find anything obvious and thought I'd ask before rolling my own...
Gavin Bisesi
@Daenyth
Should be able to do it with a regex
intellij and vsc should be able to support backrefs like that
Adam Rosien
@arosien
i'm guessing the hope is that scalafix can easily do this. but i'm not sure that's the case.
where easily would be something like $ scalafix replaceType 'scalaz.\/' 'scala.Either'
Martijn
@martijnhoekstra:matrix.org
[m]
There is a replaceSymbol
I'm guessing (though you'd have to try) it won't convert infix A \/ B to Either[A, B]
Toby
@tobyweston
Ok thanks, it won’t be a big deal if I have to do it by hand. Cheers
Gavin Bisesi
@Daenyth
I did that exact thing a while back. It was easy
nafg
@nafg
@tobyweston a strategy I sometimes use it to introduce a type alias, then rename it
At that point you have code using mypackage.Either, a type alias to scala.Either. Then you can easily remove the imports
If has a different API then instead of a type alias, it would be a thin wrapper
Shane Delmore
@ShaneDelmore
Is there a way to run the same tests that run using sbt test/unit from intellij?
I checked mUnit docs and it says it should just work, but I see when running sbt unit/test that I have some failing tests locally, and that many tests run, where when I right click scalafix-tests/unit from intellij and run tests only 6 tests run and they all pass.
Shane Delmore
@ShaneDelmore
Found it, I have to run the generated tests in the .cross directory.
Colt Frederickson
@coltfred
This message was deleted
Meriam Lachkar
@mlachkar
@all/ v0.9.25 is out, thanks to the contributors! We have mainly added the support for scala 2.12.13 and a bug fix for Patch.replaceSymbols that affects ScalaTest rule
https://github.com/scalacenter/scalafix/releases/tag/v0.9.25
https://github.com/scalacenter/sbt-scalafix/releases/tag/v0.9.25
Ruben Costa
@rubencosta
Hi here, is there a way to run scalafix with scala 3.0? This is what I added to build.sbt
scalaVersion := "3.0.0-M3", addCompilerPlugin( "org.scalameta" %% "semanticdb-scalac" % "4.4.6" cross CrossVersion.full ), scalacOptions += "-Yrangepos"
And the dependency is not found
[error] (update) sbt.librarymanagement.ResolveException: Error downloading org.scalameta:semanticdb-scalac_3.0.0-M3:4.4.6 [error] Not found [error] Not found [error] not found: /home/user/.ivy2/localorg.scalameta/semanticdb-scalac_3.0.0-M3/4.4.6/ivys/ivy.xml [error] not found: https://repo1.maven.org/maven2/org/scalameta/semanticdb-scalac_3.0.0-M3/4.4.6/semanticdb-scalac_3.0.0-M3-4.4.6.pom [error] not found: https://jcenter.bintray.com/org/scalameta/semanticdb-scalac_3.0.0-M3/4.4.6/semanticdb-scalac_3.0.0-M3-4.4.6.pom [error] not found: https://maven.pkg.github.com/fernarzt/_/org/scalameta/semanticdb-scalac_3.0.0-M3/4.4.6/semanticdb-scalac_3.0.0-M3-4.4.6.pom
Meriam Lachkar
@mlachkar
Hello, Right now, scalafix wont work with scala3.
For scala3, Semanticdb is not enabled trough addCompilerPlugin but you need to add a scalacOption which is -Xsemanticdb or you can use a newer version of sbtsbt.version=1.5.0-M1 and add in your build file ThisBuild / semanticdbEnabled := true