by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 09 10:44
    bjaglin opened #1204
  • Jul 09 07:37
    mlachkar commented #1196
  • Jul 09 06:04
    fthomas commented #1196
  • Jul 09 06:03
    bjaglin commented #1203
  • Jul 09 06:03
    bjaglin commented #1203
  • Jul 09 05:50
    bjaglin commented #1196
  • Jul 09 05:42
    bjaglin commented #1196
  • Jul 09 05:40
    bjaglin review_requested #1203
  • Jul 09 05:40
    bjaglin review_requested #1203
  • Jul 09 05:39
    fthomas commented #1196
  • Jul 09 05:34
    bjaglin edited #1203
  • Jul 09 05:34
    bjaglin opened #1203
  • Jul 09 05:29
    japgolly commented #1196
  • Jul 09 05:28
    japgolly commented #1196
  • Jul 09 05:28
    japgolly commented #1196
  • Jul 09 05:24
    bjaglin commented #1196
  • Jul 09 05:23
    bjaglin commented #1196
  • Jul 09 05:14
    bjaglin commented #1196
  • Jul 09 05:13
    bjaglin commented #1196
  • Jul 09 05:12
    bjaglin commented #1196
Dmytro Mitin
@DmytroMitin
@julienrf Patches should compose with + if they don't use replaceTree.
Julien Richard-Foy
@julienrf
Thanks @DmytroMitin. So I did two mistakes: I didn’t enable -P:semanticdb:synthetics:on and I’m using replaceTree all over the place.
Ólafur Páll Geirsson
@olafurpg
@julienrf what if you change “rename” into “replace”? My bad
it shouldn’t be necessary to implement a custom rule for the most simple cases of renames
Julien Richard-Foy
@julienrf
Would it be possible to define a rule that applies several rules? I would like my users to only run one rule, but I’m happy to reuse the existing replace rule.
Dmytro Mitin
@DmytroMitin

@julienrf

class MyRule3 extends SemanticRule("MyRule3") {
  override def fix(implicit doc: SemanticDocument): Patch = {
    Seq(new MyRule1, new MyRule2)
      .map(_.fix(doc))
      .asPatch
  }
}

You'll have to publishLocal rules.

Julien Richard-Foy
@julienrf
@DmytroMitin The docs say that replaceTree is a shorthand for removeToken and addRight. If I use removeToken and addRight instead of replaceTree I’m going to have the same issues as with replaceTree, right?
Julien Richard-Foy
@julienrf
In the end, I’m not sure how I can solve my issue of having rules that overlap. I’m using replaceTree but I’m not sure what else I should be using, because it seems that replaceTree is equivalent to removeToken + addRight? The other solution I imagined was to find a way to combine two rules sequentially, and parse the output of the first rule to give it as an input to the second one, but there seems to be nothing in scalafix to support that (I will just issue two scalafix command).
Julien Richard-Foy
@julienrf
Forget what I’ve said, I can’t do that since my rules are both semantic rules, so the code needs to compile after I apply the first rule, which is not possible in my case. So, I’ll have to implement my stuff as a single rule.
Marcin Szałomski
@baldram
Thank you @bjaglin for IDE integration-related information.
jeremyrsmith
@jeremyrsmith

Is there a good way to match a tree based on whether it's overriding a particular method? E.g. if $OLD has something like

trait Foo {
  def method: String
}

and $NEW has made it final def method: String = "I'm final now!", I want to target a (semantic) fix at any override of that method and remove the override.

jeremyrsmith
@jeremyrsmith
I think I figured it out, just match on the method name and ensure the owner extends Foo by recursively checking parents
(unless there's a better way)
Dmytro Mitin
@DmytroMitin
@jeremyrsmith beware of overloads (method with the same name not necessarily overrides)
jeremyrsmith
@jeremyrsmith
Appreciate the warning... I think in this case it should be OK.
Brice Jaglin
@bjaglin

@/all Scalafix 0.9.18 is out, thanks to all contributors!

Highlights of this release for users

  • support for Scala 2.13.3
  • ExplicitResultTypes can now be run with the sbt plugin on projects using 2.11.12, 2.12.{9,10,11} or 2.13.{1,2,3} (scalafixScalaBinaryVersion needs to be set, for 2.11 or 2.13, see documentation)
  • the sbt plugin has now a scalafixAllcommand to run scalafix across configurations

Highlights of this release for rule authors

Ólafur Páll Geirsson
@olafurpg
🥳🥳 amazing work on the release!
Manu Zhang
@manuzhang
Hi, has anyone seen this error when running scalafix --scalac-options -Ywarn-unused --rules RemoveUnused -f *.scala ?
error: error while loading Object, Missing dependency 'object scala.native in compiler mirror', required by /Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home/jre/lib/rt.jar(java/lang/Object.class)
Brice Jaglin
@bjaglin
@manuzhang I assume you are using the CLI directly, are you starting it via Coursier? Is that with a regression with a specific scalafix/scala version? bumping the patch release for Scala and/or the JVM might help.
Ólafur Páll Geirsson
@olafurpg
@manuzhang the classpath argument is required to run semantic rules.
Manu Zhang
@manuzhang
I'm following the command line guide https://scalacenter.github.io/scalafix/docs/users/installation.html#command-line @olafurpg what are required on the classpath ?
Brice Jaglin
@bjaglin
@manuzhang the --classpath argument (targeting the output of your sources when scalac is run) is required so that Scalafix can find information from the compiler (bytecode and semanticDB)
Manu Zhang
@manuzhang
Thanks, do you mean the target/scala-2.11/classes folder ? And do we have an example to fix imports of a single file ? @bjaglin
Brice Jaglin
@bjaglin
@manuzhang exactly - we don't, but that's definitely something we should add to the documentation in https://scalacenter.github.io/scalafix/docs/users/installation.html#command-line. By the way, you probably know that, but if you use a plugin for your build tool (sbt, mill, gradle), you don't have to deal with that.
Ólafur Páll Geirsson
@olafurpg
@manuzhang you can fix an individual file with the sbt plugin.
Brice Jaglin
@bjaglin
sbt-scalafix 0.9.18 introduced a massive performance regression related to classloading (particularly visible if you have many sub-projects) - scalacenter/sbt-scalafix#142 brings back 0.9.17 behavior
slivkamiro
@slivkamiro

Hi, I'm trying to configure scalfix in sbt. I'm using sbt-scalafix 0.9.18 and scala 2.13.3. I was following the installation page. But I'm always getting

Note: Unresolved dependencies path:
2020.07.07 14:02:00 INFO  [error] sbt.librarymanagement.ResolveException: Error downloading org.scalameta:semanticdb-scalac_2.13.3:4.1.0
2020.07.07 14:02:00 INFO  [error]   Not found
2020.07.07 14:02:00 INFO  [error]   Not found
2020.07.07 14:02:00 INFO  [error]   not found: /home/miro/.ivy2/local/org.scalameta/semanticdb-scalac_2.13.3/4.1.0/ivys/ivy.xml
2020.07.07 14:02:00 INFO  [error]   not found: https://repo1.maven.org/maven2/org/scalameta/semanticdb-scalac_2.13.3/4.1.0/semanticdb-scalac_2.13.3-4.1.0.pom

Have you seen this error before? Is there a way how to fix it?

Brice Jaglin
@bjaglin
@slivkamiro I am guessing you use sbt 1.3.x? you might be missing semanticdbVersion := scalafixSemanticdb.revision either at the build level or the project level depending on where you flipped semanticdbEnabled
slivkamiro
@slivkamiro

@bjaglin yes, I'm on sbt 1.3.x, this is my build.sbt

lazy val root = (project in file("."))
  .settings(
    scalaVersion := "2.13.3",
    organization := "me.slivkamiro",
    name := "project",
    version := "1.0",
    scalacOptions += "-Ywarn-unused-imports",
    semanticdbEnabled := true,
    semanticdbVersion := scalafixSemanticdb.revision,
    testFrameworks += new TestFramework("munit.Framework"),
    libraryDependencies ++= Seq(
      ...
    )
  )

So I'm not sure, I have the semanticdbVersion there, I even tried to change it to different value, but result is still the same.

Brice Jaglin
@bjaglin
try to run show semanticdbVersion and inspect semanticdbVersion to understand where/how 4.1.0 comes from (I think it's the default)
slivkamiro
@slivkamiro
Well, now it's getting weird, show semanticdbVersion returns 4.3.18 :confused:
Brice Jaglin
@bjaglin
@slivkamiro but it's still trying to download 4.1.0? is it overriden somehow in your libraryDependencies? what does libraryDependencies give you?
slivkamiro
@slivkamiro
In libraryDependencies I've got these
      "org.typelevel" %% "cats-core" % "2.1.1",
      "org.typelevel" %% "cats-effect" % "2.1.3",
      "co.fs2" %% "fs2-core" % "2.4.0",
      "io.chrisdavenport" %% "log4cats-slf4j" % "1.1.1",
      "org.apache.logging.log4j" % "log4j-core" % "2.13.3",
      "org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.13.3",
      "org.scalameta" %% "munit" % "0.7.9" % "test"
Brice Jaglin
@bjaglin
I meant: what's the output of librarydependencies when invoked/resolved in sbt?
slivkamiro
@slivkamiro
[info] * org.scala-lang:scala-library:2.13.3
[info] * org.typelevel:cats-core:2.1.1
[info] * org.typelevel:cats-effect:2.1.3
[info] * co.fs2:fs2-core:2.4.0
[info] * io.chrisdavenport:log4cats-slf4j:1.1.1
[info] * org.apache.logging.log4j:log4j-core:2.13.3
[info] * org.apache.logging.log4j:log4j-slf4j-impl:2.13.3
[info] * org.scalameta:munit:0.7.9:test
Brice Jaglin
@bjaglin
actually the compiler plugin should appear in allDependencies according to https://github.com/sbt/sbt/blob/1.3.x/main/src/main/scala/sbt/plugins/SemanticdbPlugin.scala, can you check?
10 replies
Brice Jaglin
@bjaglin
sbt-scalafix 0.9.18-1 is now available on Maven Central with fixes for scalacenter/scalafix#1196 & for performance regressions introduced in 0.9.18
Timothy Bess
@tdbgamer
Has anyone found an automated way to disable -Xfatal-warnings just for scalafix runs?
Timothy Bess
@tdbgamer
also all the examples of scalafix usage seems to require passing all the rules you want to run manually each time. I see there's a list of rules that can be added to .scalafmt.conf. Is there a way to just run scalafix or something and have it just apply all those rules automatically?
Brice Jaglin
@bjaglin
@tdbgamer there is: if you run scalafix without any explicit rules, the ones defined in the configuration will be executed
Brice Jaglin
@bjaglin
@tdbgamer we are using this, and it's been working OK (the incOptions might silence some warnings if you run scalafix before compile, but we didn't find it to be a big problem)
      scalacOptions --= {
        if (!scalafixRunExplicitly.value) Seq() else Seq("-Xfatal-warnings")
      }
      // don't let the removal of `-Xfatal-warnings` invalidate the cache for previous successful compilations
      incOptions := incOptions.value.withIgnoredScalacOptions {
        if (!scalafixRunExplicitly.value) Array() else Array("-Xfatal-warnings")
      }
  private def scalafixRunExplicitly: Def.Initialize[Task[Boolean]] =
    Def.task {
      executionRoots.value.exists { root =>
        Seq(
          scalafix.key,
          scalafixAll.key
        ).contains(root.key)
      }
    }
Brice Jaglin
@bjaglin
Timothy Bess
@tdbgamer
@bjaglin thanks for all the tips! I'll try out those last two things, shadowy looks super useful. I actually tried running scalafix without anything to see if it would pickup the config but it was still unhappy that I didn't pass any --rules
7 replies
Ólafur Páll Geirsson
@olafurpg
scalafix.png
@mlachkar @bjaglin @liancheng In case you are curious, here are the download numbers for scalafix-interfaces over the past year
Screenshot 2020-07-09 at 09.41.25.png
Most of the downloads come from recent versions. With all the recent activity I wouldn't be surprised to see the growth continue.
Brice Jaglin
@bjaglin
Thanks for sharing! I guess https://github.com/scala/scala-rewrites & https://github.com/scalatest/autofix will continue to drive usage considering the agressive deprecation strategies for scala 2.13 & scalatest.
Although the killer rule probably remains @liancheng's OrganizeImports!
Brice Jaglin
@bjaglin
I am porting upstream a sbt feature we have been using internally for a while: scalafixOnCompile -> scalacenter/sbt-scalafix#140 feedback welcome, as I guess we are not the only ones with this approach