Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 02:10
    scala-steward opened #1611
  • May 24 16:52
    scala-steward opened #1610
  • May 24 11:16
    marcelocenerine removed as member
  • May 24 11:15
    vovapolu removed as member
  • May 24 11:15
    ShaneDelmore removed as member
  • May 24 09:52

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • May 24 09:51

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • May 24 09:48

    mlachkar on main

    Update scalameta, semanticdb-sc… (compare)

  • May 24 09:48
    mlachkar closed #1609
  • May 24 09:48

    mlachkar on main

    Update scalafmt-core to 3.5.4 (… (compare)

  • May 24 09:48
    mlachkar closed #1608
  • May 23 07:47

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • May 23 07:43

    mlachkar on main

    I want to add my rules to commu… (compare)

  • May 23 07:43
    mlachkar closed #1607
  • May 19 10:59
    tanishiking commented #1607
  • May 19 10:08
    Javakky-pxv commented #1607
  • May 19 10:07
    Javakky-pxv commented #1607
  • May 18 22:47
    scala-steward opened #1609
  • May 18 19:51
    scala-steward closed #1606
  • May 18 19:51
    scala-steward commented #1606
Ólafur Páll Geirsson
@olafurpg
There’s no automatic solution to handle the blank lines
Raúl Piaggio
@rpiaggio
@olafurpg Thanks for the info, I hadn't realized about the trailing token API, I think I can work with that.
Ólafur Páll Geirsson
@olafurpg
It’s low-level and error prone to work with tokens. But you can usually achieve what you want if you put enough effort (and write lots of tests!)
Meriam Lachkar
@mlachkar

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

Highlights

Full changelog

Rohan Sircar
@rohan-sircar
:tada:
Sakib Hadžiavdić
@sake92
Hello! First time using scalafix.
I have this class: class NoOp4(implicit final val s: String)
And when I print parameters' mods: List(, final, val)
The implicit one is empty
Sakib Hadžiavdić
@sake92
my bad, I used cls.mods.contains(..) instead of cls.symbol.info.get.isStuff...
Raúl Piaggio
@rpiaggio
is there a way to attempt to evaluate a tree that only depends on constants?
ie: a string that is concatenated in code
Sakib Hadžiavdić
@sake92
is it possible to run scalafix on a scala3 project?
Ben Plommer
@bplommer
Not yet, there's an issue for it: scalacenter/scalafix#1316
Ólafur Páll Geirsson
@olafurpg
@rpiaggio i’m not aware of any partial evaluator
Raúl Piaggio
@rpiaggio
thx
Raúl Piaggio
@rpiaggio
If I understand correctly, scalafix doesn't currently provide the tree AFTER macro expansions, is that right?
Ó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 )