Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 07:47

    mlachkar on gh-pages

    Deploy website Deploy website … (compare)

  • 07:43

    mlachkar on main

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

  • 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
  • May 18 19:51
    scala-steward opened #1608
  • May 18 08:18
    tanishiking commented #1607
  • May 18 05:32
    Javakky-pxv opened #1607
  • 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
Raúl Piaggio
@rpiaggio
Ok, I think I'm missing something obvious. In the fix method of my rule, I want to remove some definitions by using doc.tree.collect { case tree: Defn..... => Patch.removeTokens(tree.tokens) }. However, this leaves behind a blank line. (I haven't tried but I guess it may leave behind a ; if there are other statements in the same line). Is there an easy way to remove said blank line?
The actual case is that I'm regenerating a definition, so I remove if it's there and add it back again. But repeated applications of the rule start accumulating blank lines. Maybe there another strategy for regenerating?
Ólafur Páll Geirsson
@olafurpg
@rpiaggio the context has an api to walk through the trailing tokens.
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