Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 14 01:50
    scala-steward opened #1606
  • May 12 06:32
    mlachkar commented #1583
  • May 08 08:51

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • May 08 08:48

    bjaglin on main

    Update scalameta, semanticdb-sc… Merge pull request #1605 from s… (compare)

  • May 08 08:48
    bjaglin closed #1605
  • May 05 16:39
    scala-steward opened #1605
  • May 01 21:43

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • May 01 21:40
    bjaglin commented #1594
  • May 01 21:40

    bjaglin on main

    Update scalameta, semanticdb-sc… Merge pull request #1604 from s… (compare)

  • May 01 21:40
    bjaglin closed #1604
  • May 01 21:40
    bjaglin closed #1594
  • May 01 21:32
    bjaglin commented #1604
  • May 01 21:25
    bjaglin synchronize #1604
  • Apr 30 23:09
    scala-steward opened #1604
  • Apr 23 14:24
    tanishiking commented #1594
  • Apr 23 00:36
    SethTisue commented #1575
  • Apr 23 00:35
    SethTisue commented #1575
  • Apr 22 14:26
    tgodzik commented #1594
  • Apr 22 13:52
    tanishiking commented #1594
  • Apr 22 13:14
    rochala commented #1594
Ólafur Páll Geirsson
@olafurpg
the older version is only evicted within a single resolution, and my understanding is that custom rules are resolved via a separate resolution (but I may be missing something)
Brice Jaglin
@bjaglin
Even though it's indeed 2 separate resolutions (the first one in scalafix-interfaces, and the second one in scalafix-cli), I naively thought the filtering strategy used to sandbox scalafix-cli behind scalafix-interfaces could be adapted so that classloaded rules share only scalafix.v1.* (or something like that) with the scalafix-cli classloader. But after looking at the code, I realized some scalameta/metaconfig types are exposed through scalafix.v1.*, so that lack of clear boundaries makes it impossible to get both sandboxing AND class unicity across classloaders.
Brice Jaglin
@bjaglin
Since the toolclasspath is most often known beforehand, we could add some methods in scalafix-interfaces that classload scalafix-cli AND custom rules in one go though. The problem I see is that the CLI itself wouldn't benefit from that, so for the same scalafix-cli/interfaces version, behavior would be different between a pure CLI invocation and one through a build tool / IDE.
Dario Abdulrehman
@dabd
Can you run scalafix rules on .sbt files? I wanted to apply https://github.com/liancheng/scalafix-organize-imports on these files as well.
Brice Jaglin
@bjaglin
@dabd only syntactic rules are supported on *.sbt files, so I am afraid you can't run that semantic rule
Dario Abdulrehman
@dabd
thanks @bjaglin
Michael Thomas
@Michaelt293
I'm wondering, is there a good way to go from a Symbol to the scala meta AST for that symbol?
Ólafur Páll Geirsson
@olafurpg
@Michaelt293 a symbol can be loaded from the classpath where you don’t have access to the sources. What would the AST contain?
You can render the signature of a symbol into Scala syntax, which you could parse
but you wouldn’t have the implementation then
Michael Thomas
@Michaelt293

Thanks @olafurpg , I understand that it might be a bit of a strange thing to want to do. A simplified example of what I'm trying to do is something similar to this-

  trait Level {
    def level = 1
  }

  class Example extends Level

Rewrite as-

  class Example {
    def level = 1
  }

To do this, I would need to have access to the AST for Level and Level could be defined in another file. If Level was defined in a dependency, all bets are off and I would not be able to get the AST.

Ólafur Páll Geirsson
@olafurpg
@Michaelt293 there's no straightforward way to accomplish that with the current API
One backwards way to achieve it would be to run scalafix twice, where you collect the ASTs in the first pass and persist them somehow in Rule.afterComplete() https://github.com/scalacenter/scalafix/blob/1c0ba35cc71f28551f98ea607d47f4db7147d802/scalafix-core/src/main/scala/scalafix/v1/Rule.scala#L46
but Scalafix alone doesn't really have sufficient APIs to implement this anways
when you inline code from a separate file then you need to pretty-print the original source in a way so that all the identifiers resolve to the same symbols as in the original file
ExplicitResultTypes has logic like that but you can look at the implementation to see that it's not that trivial to do correctly
I estimate it's very hard to implement this refactoring if you're aiming for >99% correctness
Brice Jaglin
@bjaglin
If you use sbt-scalafix to implement the 2-rule hack, make sure you opt-out from scalafixCaching, otherwise re-runs will only capture the AST of changed files
Michael Thomas
@Michaelt293
Thanks for the information :)
Albert Meltzer
@kitbellew
@olafurpg @bjaglin i finally decided to try scalafix, and now i need some help. how do i run scalafix-cli (we do not use sbt) with the OrganizeImports external rule? i got scalafix the same way we do with scalafmt (via coursier standalone bootstrap). ideally, the external jar is also downloaded in advance as build servers are behind firewall and might not be able to.
Ólafur Páll Geirsson
@olafurpg
@kitbellew semantic rules like OrganizeImports need access to the classpath of the project and semanticdb files of the sources being fixed. This makes it more complicated to run scalafix from the cli compared to scalafmt.
What build tool are you using?
The classpath of the OrganizeImports rule can be added via —tool-classpath
or you can also add the ruleto the same bootstrap jar as scalafix-cli
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:”