Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 24 12:45
    mlachkar commented #1518
  • Jan 24 09:36
    mlachkar commented #1526
  • Jan 24 09:28
    mlachkar commented #1518
  • Jan 23 22:00
    bjaglin edited #1528
  • Jan 23 22:00
    bjaglin edited #1528
  • Jan 23 21:59
    bjaglin opened #1528
  • Jan 22 22:08
    bjaglin commented #1522
  • Jan 22 22:08
    bjaglin commented #1522
  • Jan 22 21:59
    bjaglin commented #1522
  • Jan 22 21:37
    bjaglin synchronize #1522
  • Jan 22 20:42
    bjaglin synchronize #1522
  • Jan 21 22:10
    tgodzik commented #1522
  • Jan 21 21:38
    bjaglin commented #1522
  • Jan 21 21:38
    bjaglin commented #1522
  • Jan 21 21:26
    bjaglin synchronize #1522
  • Jan 21 21:20
    bjaglin commented #1522
  • Jan 21 21:13
    bjaglin commented #1522
  • Jan 21 21:10
    bjaglin commented #1522
  • Jan 21 21:09

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • Jan 21 21:09

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

Ólafur Páll Geirsson
@olafurpg
@rpiaggio correct. Macro-expanded trees may not even have valid syntax, macros can manually typecheck ASTs in ways that's not possible by writing source code.
Raúl Piaggio
@rpiaggio
I see, thanks :+1:
Ashwin Bhaskar
@ashwinbhaskar

how can I use regex in scalafix (using inside sbt console)?

scalafix ---rules=<somerule-url> --files=*.sbt

gives the following error

[error] --files=*.sbt
[error] missing or invalid value
Brice Jaglin
@bjaglin
I don't think wildcards are supported in the files CLI arg. Also, sbt-scalafix makes it easy to run scalafix on scala sources of modules, but will probably break in some way if you want to run on sbt files. In your case, since the rule is necessarily syntactic as semanticdb is not prorperly supported on sbt files, using the scalafix CLI (that you can install via coursier for example) would be easier, and then you can use shell for wildcard expansion.
Ashwin Bhaskar
@ashwinbhaskar
okay, thanks:)
Kirill Shelopugin
@Z1kkurat

Hey guys! I have a question about organizing imports with scalafix OrganizeImports rules. Probably not the right place to ask (point me in the right direction please).
Is there any option to have imports organized the following way?

import org.apache.kafka.clients.consumer.{
  ConsumerRebalanceListener,
  OffsetCommitCallback,
  Consumer => ConsumerJ,
  ConsumerGroupMetadata => ConsumerGroupMetadataJ,
  ConsumerRecords => ConsumerRecordsJ,
  OffsetAndMetadata => OffsetAndMetadataJ,
  OffsetAndTimestamp => OffsetAndTimestampJ
}

Current implementation just put them all on a single line like this

import org.apache.kafka.clients.consumer.{Consumer => ConsumerJ, ConsumerGroupMetadata => ConsumerGroupMetadataJ, ConsumerRebalanceListener, ConsumerRecords => ConsumerRecordsJ, OffsetAndMetadata => OffsetAndMetadataJ, OffsetAndTimestamp => OffsetAndTimestampJ, OffsetCommitCallback}
Brice Jaglin
@bjaglin
@Z1kkurat I can only comment as a user of that rule, but I don't think that's possible. I would suggest logging a feature request through https://github.com/liancheng/scalafix-organize-imports/issues.
Meriam Lachkar
@mlachkar
I guess the combination with scalafmt would produce this, but It's not what you are asking for!
Kirill Shelopugin
@Z1kkurat
I found an issue (liancheng/scalafix-organize-imports#43) and the author claims it should be fixed as of now. Probably metals is using an old version of the library, will check that
@liancheng sorry to bother you, maybe you can comment on that?
Ólafur Páll Geirsson
@olafurpg
@Z1kkurat FWIW, it's normal that Scalafix don't emit formatted code. It's better to use Scalafmt to make sure that the fixed output matches the coding style of your project.
If every Scalafix rule takes on the responsibility to emit perfectly formatted code, then every rule ends up reimplementing most of Scalafmt configuration options
If you don't use a code formatter like Scalafmt, then I think it's normal that you have manually fix the formatting of the Scalafix output.
Kirill Shelopugin
@Z1kkurat
Actually I do use scalafmt and yeah, I have no objections to what you said. It's just that I have found an issue which states that it was fixed and scalafmt rules are respected and I would like to know if that's an expected behaviour of rule or not.
Ólafur Páll Geirsson
@olafurpg
I think it's expected behavior that the organize-imports rule emits a single long line
(without having read through the release notes or issues)
Cheng Lian
@liancheng

@Z1kkurat, thanks for reaching out. For liancheng/scala-organize-imports#43, the fix I made is to make sure that if an import statement is already organized according to the configuration, OrganizeImports should preserve the original format (line breaks, spaces, etc.). As @olafurpg pointed out, Scalafix is not responsible (or capable in many cases) to emit well formatted code, and you'll need tools like Scalafmt for that.

The fix I made makes OrganizeImports idempotent. For example, if you run Scalafix first to organize the imports, run Scalafmt to format the code, and then run Scalafix again, the 2nd Scalafix run should not reformat your code since your imports are already organized. Please refer to this section for more details.

In the case you reported, the original import statement is not organized yet (not sorted properly), so OrganizeImports updated and reformatted it.

Tushar Mathur
@tusharmath
Is there a scalafix rule that can automatically sort the methods defined in a trait?
or class, or companion object.
Tushar Mathur
@tusharmath
I have written this fix
  val patch = doc.tree.collect { case t: Template =>
      val otherDefinition = t.stats.filterNot(_.isInstanceOf[Defn.Def])
      val defDefinition = t.stats.collect({ case d: Defn.Def => d }).sortBy(_.name.value)
      Patch.replaceTree(t, t.copy(stats = otherDefinition ++ defDefinition).syntax)
    }
Im simply separating the def from the others and then sorting it.
It doesn't work recursively though, as in — if you have a trait inside a trait etc.
and you want to sort the methods in it.
Tushar Mathur
@tusharmath
Ólafur Páll Geirsson
@olafurpg
@tusharmath cool! Thank you for sharing!
What happens when you have docstrings or comments?
Tushar Mathur
@tusharmath

Original

trait AB {
  /*
   * Some description about `b`
   */
  def b: Unit
  def a: Unit
}

Fixed

trait AB {
  /*
   * Some description about `b`
   */
  def a: Unit
  def b: Unit
}
@olafurpg
BTW I was able to solve the recursive problem somehow.
Right now the comments get really messed up :P
Markus Appel
@markusa380

Probably a dumb question, but how can I find type information for a reference?
E.g.

val r: zio.Runtime[Any] = ???

// Somewhere in the program
r.platform

I want to find SymbolInformation for r but it's always None, and r could be defined anywhere so I need to somehow lookup it's type?

Manel Pérez
@manelp

Hi, is there any know problem with scalafix 0.9.27 and scala 2.12.13? I'm getting a trace showing the tree, I suppose from semanticdb, when I have any compilation error:

TRANSFORM: null                                                                                                                                                                                                                      
TREE:
...

I've tried downgrading to scala 2.12.12 and it worked fine, and with scala 2.13.4 also works fine

Brice Jaglin
@bjaglin
@manelp it doesn't ring a bell, do you have a repro? are you using sbt-scalafix?
Manel Pérez
@manelp
Yes, sbt-scalafix. I'll try to reproduce it in a small project.
Manel Pérez
@manelp

Ok, I've found out that the problem is a combination of two compiler plugins:

name := "sbt-scalafix-test"

version := "0.1"

scalaVersion := "2.12.13"

lazy val root = project
  .in(file("."))
  .settings(
    addCompilerPlugin(scalafixSemanticdb),
    addCompilerPlugin("com.github.ghik" % "silencer-plugin" % "1.7.3" cross CrossVersion.full)
  )

With both enabled, sbt compile finish with a success, but it shouldn't because there errors. Commenting out any of them solves the problem. Here's the repo were I've tried this: https://github.com/manelp/sbt-scalafix-test.
I will drop silencer since I can use @nowarnnow and won't invest more time on this, but I leave it here for anyone who may face this problem

Brice Jaglin
@bjaglin
thanks for the repro! you should follow up on https://gitter.im/scalameta/scalameta or https://github.com/scalameta/scalameta/issues, that's where semanticdb-scalac is maintained (although I am not sure where the responsibility lies between the 2 plugins and the compiler - which by the way will see a 2.12.14 release anytime now, so your problem might be gone )
Manel Pérez
@manelp
:+1:
Meriam Lachkar
@mlachkar

Scalafix 0.9.28 with support for Scala 3

We are happy to announce the release of Scalafix 0.9.28.Huge thanks to bjaglin and taisukeoe for their great contributions (release notes: 1, 2).

This release brings many improvements, in particular it introduces support of Scala 3 for both users and rule authors.

Highlights of this last release:

  • Support Scala 3: it’s still experimental and some built-in rules may not work as expected. We started testing some community rules on Scala 3, one of them is the popular organize-imports rule. Most tests are passing except the ones relying on the Wunused scalacOption which is not yet supported by Scala 3 compiler. Some other rules will work out-of-the box with Scalafix 0.9.28, even if the source files use features or syntax introduced in Scala 3. We invite all rule authors to test their rules against Scala 3 and to adapt, if needed, the required scalacOptions (example of the on-going liancheng/scalafix-organize-imports#179 on scalafix-organize-imports)
  • Update Tthe Scalafix.g8 template: to make it simple to test rules against Scala 3 source files. To test it you can run sbt new scalacenter/scalafix.g8
  • Drop SemanticRuleSuite and SyntacticRuleSuite: those two classes were already deprecated since 0.9.18 and we have created a migration rule to make the migration automatic for most cases. This will unlock the upgrade of scalatest for next versions.
  • Caching is now enabled by default on sbt-scalafix: successive invocations of the scalafix task with the same arguments & configuration will be incremental. This was already the case when scalafixOnCompile was enabled, but we believe this can improve user experience also for users starting scalafix sporadically.
  • Support of Scala 2.13.6 & -Xsource:3
  • Support on-compile specific configuration: scalacenter/scalafix#1375
Chris Kipp
@ckipp:matrix.org
[m]
🎉 congrats that a huge release!
1 reply
Romain DEP.
@rom1dep
Hello there!
I was trying to code my first rewrite rules at: https://gist.github.com/rom1dep/4127f5c0a2000703fe6f22d7dd9ad3c2
to help this project out: scalafx/scalafx#352 , but I'm very new to this, and quite convinced now that I'm taking this problem from the wrong end. Is scalafix the right tool for the job? And if so, any advise as to a more reasonable approach?
4 replies
Ondra Pelech
@sideeffffect

I'm getting unexpected errors when trying to upgrade to sbt-scalafix 0.9.28: zio/zio-prelude#634

[error] SemanticDB not found: core/shared/src/test/scala/zio/prelude/AssociativeFlattenSpec.scala
[error] SemanticDB not found: core/shared/src/test/scala/zio/prelude/CoherentSpec.scala
[error] SemanticDB not found: core/shared/src/test/scala/zio/prelude/SafeFunctionSpec.scala
...

How can I fix this? Thank you

11 replies
Romain DEP.
@rom1dep
how am I supposed to replace a tree with another tree rather than with a string?
38 replies
Ondra Pelech
@sideeffffect
Hello, will you publish a new version which supports ScalaMeta 4.4.20 (which supports Scala 2.12.14) anytime soon?
Brice Jaglin
@bjaglin
@sideeffffect i was waiting for a dependency release to address scalacenter/scalafix#1414, but I will just rollback, and tag
Ondra Pelech
@sideeffffect
thank you!
Brice Jaglin
@bjaglin
@/all Scalafix 0.9.29 is out, fixing 2 regressions introduced in 0.9.28 and adding support for Scala 2.12.14. Thanks @tgodzik for the quick turnaound as usual!
Ondra Pelech
@sideeffffect
Thank you @bjaglin for releasing this so quickly!!! :bow:
Ondra Pelech
@sideeffffect
Btw, one has to use scaluzzi 0.1.18 (not the newest 0.1.19) because of old metaconfig that is used in 0.9.29. Otherwise one gets
Error:  java.lang.NoSuchMethodError: 'void metaconfig.generic.Surface.<init>(scala.collection.immutable.List, scala.collection.immutable.List)'
Error:      at scalafix.internal.scaluzzi.DisableConfig$.<init>(DisableConfig.scala:162)
Brice Jaglin
@bjaglin
Oops, that's scalacenter/scalafix#1418... That also means scaluzzi 0.1.19 or any rule built against Scalafix 0.9.28 making use of metaconfig.generic.Surface will not run on Scalafix<0.9.28, which is as concerning, if not more.