Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 10 22:22
    bjaglin commented #1393
  • May 10 17:34
    mlachkar reopened #1393
  • May 10 17:34
    mlachkar commented #1393
  • May 10 17:31
    mlachkar commented #1393
  • May 10 16:44
    mlachkar closed #1393
  • May 10 16:44
    mlachkar commented #1393
  • May 10 14:08
    mlachkar edited #1393
  • May 10 13:22
    mlachkar edited #1393
  • May 10 13:22

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • May 10 13:19
    mlachkar review_requested #1393
  • May 10 13:19
    mlachkar synchronize #1393
  • May 10 13:19

    mlachkar on main

    remove dialect and use scalaVer… (compare)

  • May 10 13:19
    mlachkar closed #1392
  • May 10 13:18
    mlachkar opened #1393
  • May 10 13:09
    mlachkar synchronize #1392
  • May 10 12:02
    mlachkar synchronize #1392
  • May 10 12:02
    mlachkar synchronize #1392
  • May 10 11:43
    mlachkar review_requested #1392
  • May 10 10:56
    mlachkar ready_for_review #1392
  • May 10 10:55
    mlachkar synchronize #1392
Ólafur Páll Geirsson
@olafurpg
@jatcwang you can use scala.meta.Term.Name(..).toString
Jacob Wang
@jatcwang
@olafurpg thank you!
Francois Armand
@fanf
I have that error in scalafix, should I report it (open bug report etc?) es/policies/DeploymentService.scala:877: error: Invalid literal number PolicyGenerationLogger.timing.debug(s"Merge group properties took ${timeNanoMergeProp/(1_000_000)} ms for ${nodeIds.size} nodes") ^ at scala.meta.internal.tokenizers.Reporter.syntaxError(Reporter.scala:23)
sorry for the format: the problem is that the tokenizers doesn't understand 1_000_000
Francois Armand
@fanf

I have an other one:

<button type="button" ng-click="addTag(newTag)" class="btn btn-success btn-sm" ng-disabled=" (isEmptyOrBlank(newTag.key) && isEmptyOrBlank(newTag.value)); ">
[ERROR]                                                                                                                     ^
[ERROR]     at scala.meta.internal.tokenizers.Reporter.syntaxError(Reporter.scala:23)

Should I open bug report for it?

Meriam Lachkar
@mlachkar
Hello, those errors seem to be related more to scalameta than scalafix. I think It could be interesting to report them to scalameta repo and ask for feedbacks.
Francois Armand
@fanf
ok, thanks!
xplosunn
@xplosunn
Hey, I created a custom Scalafix rule that I put the source code on github ( https://github.com/xplosunn/JsonMacroFormatter ). I don't know how to proceed regarding publishing it somewhere and then how to use it in another project. Any pointers? Thanks
xplosunn
@xplosunn
@bjaglin Going through it now. Thanks!
Felipe Vieira
@fmv1992

Hi, everyone, has anyone experienced:

$ sbt
[info] Loading settings for project example-build from plugins.sbt ...
[info] Loading project definition from /tmp/tmp.RLm3LqJokA/example/project
[info] Updating ProjectRef(uri("file:/tmp/tmp.RLm3LqJokA/example/project/"), "example-build")...
[info] Done updating.
/tmp/tmp.RLm3LqJokA/example/build.sbt:13: error: not found: value semanticdbEnabled
semanticdbEnabled := true,
^
/tmp/tmp.RLm3LqJokA/example/build.sbt:14: error: not found: value semanticdbOptions
semanticdbOptions += "-P:semanticdb:synthetics:on", // make sure to add this
^
/tmp/tmp.RLm3LqJokA/example/build.sbt:15: error: not found: value semanticdbVersion
semanticdbVersion := scalafixSemanticdb.revision,
^
[error] Type error in expression

?

More details at scala/scala-rewrites#67

2 replies
Brice Jaglin
@bjaglin

@/all scalafix 0.9.23 is out! (please skip 0.9.22 which had an unnecessary breaking change)

Highlights

Dan Di Spaltro
@dispalt
Has anyone tried to create a rule to replace something like monix.execution.Task with cats.effects.IO?
nafg
@nafg
@dispalt idk about a rule but here's a strategy:
Create a type alias that shadows Task of IO
Then you get compiler errors of missing methods, add them as extension methods
Then rename and/or online the methods to make them redundant
Then rename the type alias to make it redundant
Or inline it
Renaming and inlining are general refactorings, if scalafix support needs to be improved that's easier
Then it's a sequence of steps that you can do yourself
Dan Di Spaltro
@dispalt
yeah I was considering that approach and then figured it would be nice to try my hand at scalafix and so now I've gone through some old code I am starting to get the hang of it
@nafg thanks for the help
Andy Kirsch
@AndyKirsch
Can a scalafix rule rewrite a build.sbt file? Answer appears to be no, but I can't find anything definitive saying you can't
17 replies
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