Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 26 2017 22:35
    olafurpg synchronize #947
  • May 26 2017 22:23
    olafurpg synchronize #947
  • May 26 2017 22:22
    olafurpg synchronize #947
  • May 26 2017 22:20
    olafurpg opened #947
  • May 26 2017 22:07
    olafurpg commented #943
  • May 26 2017 21:53

    olafurpg on v1.0.0-RC1

    (compare)

  • May 26 2017 21:46

    olafurpg on master

    Upgrade to non-broken metaconfi… Merge pull request #946 from ol… (compare)

  • May 26 2017 21:46
    olafurpg closed #946
  • May 26 2017 21:25
    olafurpg opened #946
  • May 26 2017 14:44

    olafurpg on master

    documentation fix: binPackParen… Merge pull request #945 from na… (compare)

  • May 26 2017 14:44
    olafurpg closed #945
  • May 26 2017 14:43
    olafurpg commented #943
  • May 26 2017 14:39
    olafurpg commented #943
  • May 26 2017 14:03
    pjrt commented #943
  • May 26 2017 13:36
    pjrt commented #943
  • May 26 2017 13:12
    nadavwr opened #945
  • May 25 2017 22:57
    ScalaWilliam commented #943
  • May 25 2017 21:34
    pauldraper commented #890
  • May 25 2017 21:34
    pauldraper commented #890
  • May 25 2017 17:23
    olafurpg commented #943
heksesang
@heksenlied:matrix.org
[m]
I assume everyone understands that, because if it was understood as anything else it would mean that scalafmt is pure magic. :P
swoogles
@swoogles
Re-asking-
Hey all, I've got a project where markdown files include fenced Scala snippets.
Is there any sort of standard approach for applying scalafmt to those snippets and altering them in-line?
Or is that not a proper use case for scalafmt, and it's really intended for .scala files only?
1 reply
Hugo van Rijswijk
@hugo-vrijswijk
Is there a (rewrite) rule to format import x.{Y}to import x.Y for single-item imports?
3 replies
I can't find one in the configuration. Would it be a welcome addition?
Tomasz Godzik
@tgodzik
@swoogles you could use mdoc in that case with a custom string modifier that would invoke scalafmt
I think scalafmt itself does soemthing similar
thoguh, more complciated than that
@hugo-vrijswijk RedundantBraces maybe ?
heksesang
@heksenlied:matrix.org
[m]

Currently I am seeing:

inline def summonConfigReaders[T <: Tuple]: List[ConfigReader[_]] =
  inline erasedValue[T] match {
    case _: (h *: t) =>
      inline erasedValue[h] match {
        case _: Tuple => deriveForTuple[h & Tuple] :: summonConfigReaders[t]
        case _ => summonInline[ConfigReader[h]] :: summonConfigReaders[t]
      }

    case _: EmptyTuple => Nil
  }

being corrected to:

inline def summonConfigReaders[T <: Tuple]: List[ConfigReader[_]] =
  inline erasedValue[T] match {
    case _: (h *: t) =>
        inline
      erasedValue[h] match {
        case _: Tuple => deriveForTuple[h & Tuple] :: summonConfigReaders[t]
        case _ => summonInline[ConfigReader[h]] :: summonConfigReaders[t]
      }

    case _: EmptyTuple => Nil
  }
With 3.0.0-RC2.
Ishan Shah
@nullptr7
Intellij attempts to download the scalafmt jars from the public internet and the firewall in our org doesn't allow that. We do have scalafmt within our internal maven repository though. Is there any way we can point the Scala plugin to use a local scalafmt jar, or tell it what maven repo to download it from? Thanks
Tomasz Godzik
@tgodzik
@heksenlied:matrix.org that's a known issue
Alexandru Nedelcu
@alexandru

Hi all,

Any ideas how to fix this formatting issue? (at .via)

Flow[(A, Ctx)].map {
  case (a, ctx) =>
    rn.unsafe.logger.infoWithContext(logMsg)
    (a, ctx)
}
  .via(self)
  .map {
    case (b, ctx) =>
      rn.unsafe.logger.infoWithContext(logMsg)
      (b, ctx)
  }

I want those method calls to be on the same level. Something like this would be acceptable:

Flow[(A, Ctx)]
  .map {
    case (a, ctx) =>
      rn.unsafe.logger.infoWithContext(logMsg)
      (a, ctx)
  }
  .via(self)
  .map {
    case (b, ctx) =>
      rn.unsafe.logger.infoWithContext(logMsg)
      (b, ctx)
  }

It's fine that Scalafmt wants that .map on the same line, except when I have method chaining like this.

1 reply
Could it preserve my newlines somehow?
Tomasz Godzik
@tgodzik
@alexandru maybe newlines.source=unfold would help? Though that can influence other places
Kirill Shelopugin
@Z1kkurat

Hi everyone! I suppose there's a setting that controls the vertical alignment of case classes' named fields during their instantiation so

MyCaseClass(
  a = xxx,
  abc = yyy
)

Turns into

MyCaseClass(
  a   = xxx,
  abc = yyy
)

But I couldn’t find one. align.preset = most doesn’t seem to do the trick.
Tried 2.7.1, 2.7.5 and 3.0.0-RC2
The whole config is

version = 3.0.0-RC2
align.preset = most
continuationIndent.callSite = 2
continuationIndent.defnSite = 2
danglingParentheses.preset = true
indentOperator.preset = spray
maxColumn = 150
newlines.alwaysBeforeTopLevelStatements = true
project.excludeFilters = [".*\\.sbt"]
rewrite.rules = [RedundantParens, SortImports]
spaces.inImportCurlyBraces = false
unindentTopLevelOperators = true
Albert Meltzer
@kitbellew
Кирилл, the scalafmt configuration documentation section on align tokens contains a link to a widget which allows you to parse code using scalameta and find the tree which "owns" your desired alignment delimiter (and change the align.tokens setting appropriately). Try using it; it should be something like Term.Param or Ctor.Primary in your case.
nscarcella
@nscarcella
Hi everyone, I hope this is the right place to ask...
I'm trying the Scala 3.0.0 release and wanted to configure scalafmt in my working environment (VSCode + Metals), but the formatting action does not seem to have any effect. I updated the target scalafmt version to 3.0.0-RC2 and tried to manually run it from the console, but I see it throws errors when I use the new features (for example, defs in the package level), which makes me suspect I'm doing something wrong.
I'm not very familiar with Scala dev tools so if anybody could point me in the right direction I would be very grateful.
Tomasz Godzik
@tgodzik
@nscarcella what kinds of issues are you having? Formatting should work fine, the only problem might be that I haven't managed to be release Metals for 3.0.0 yet, but I am working on it today
nscarcella
@nscarcella

Hi @tgodzik, first time I saved VSCode offered me to create the .scalafmt.conf file (which makes me believe that the format action is getting trigger and tries to use scalfmt), but I tried a couple of settings and no rule seems to be aplied.
I updated the created .scalfmt.conf to this:

version = "3.0.0-RC2"
align.preset = more
maxColumn = 80

But saving or manually running the format document task seem to cause no effect.
I tried to manually run scalafmtfrom the console, but I get what looks like parsing errors that makes me suspect scalafmt is not supporting scala 3.0.0-RC3 version:

.../src/main/scala/fireworks/FireworksRunner.scala:18: error: expected start of definition
@main def run(): Unit =
      ^
.../src/test/scala/fireworks/FireworksSuite.scala:7: error: ; expected but , found
class FireworksSuite extends FunSuite, FireworksGenerators:
                                     ^
.../src/test/scala/fireworks/FireworksGenerators.scala:6: error: ; expected but : found
trait FireworksGenerators:
                         ^
.../src/main/scala/fireworks/Fireworks.scala:16: error: ; expected but : found
object Firework:
               ^

I thought that maybe scalafmt is failing the task and metals is just silently failing because of that.

Vadim Chelyshov
@dos65
@nscarcella you also need to add runner.dialect = scala3 in .scalafmt.conf
nscarcella
@nscarcella
@dos65 Aha! That was it! Thanks a lot!
nscarcella
@nscarcella
Aaand, of course there was a section explaining this in the documentation... I didn't want to dive into the rules until the setup was working so I completely missed the section. Should have been more thorough... Sorry and thanks again.
nscarcella
@nscarcella
Hey guys, small question: Is there a way to preserve more than one consecutive empty lines in the source? I've tried newlines.source = keep and it seems to maintain single empty lines, but whenever I try to add a two-line space between classes it drops one on them.
1 reply
Yuval Itzchakov
@YuvalItzchakov

Does anyone know if there's a way to make IntelliJ not remove spaces in imports during "optimize imports"? I have:

spaces {
  inImportCurlyBraces = true
}

Set and it's driving me nuts each time I optimize imports

nscarcella
@nscarcella

Hey guys, small question: Is there a way to preserve more than one consecutive empty lines in the source? I've tried newlines.source = keep and it seems to maintain single empty lines, but whenever I try to add a two-line space between classes it drops one on them.

Since it looks like it is not possible to avoid deleting extra empty lines, is there a way to make scalafmt just leave empty lines alone and not remove/insert any? I don't mind managing my own empty lines, but I really use the double blank line a lot to keep code from getting cramped...

Albert Meltzer
@kitbellew
@nscarcella check out scalameta/scalafmt#2511
Daniel Hinojosa
@dhinojosa
Is there a newer plugin for sbt to handle Scala 3? This is the latest I found: addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") and when I run it it tells me that Expected one of: scala212, sbt1, paradise211, scala211, paradise212, default, dotty, scala213, sbt0137 because I have runner.dialect = scala3
1 reply
Eric K Richardson
@ekrich

Is there any possible way to achieve this without doing it all by hand? https://github.com/scala-js/scala-js/blob/master/CODINGSTYLE.md#scaladoc

Basically this is Javadoc style but allowing the first line and aligning one space after the second asterisk. It would be good to allow single line as well.

The beauty of this is that it looks like C and Java comments or just multi-line comments but when you fold the comment in like VSCode or some other editor the first line still shows in the UI.

3 replies
Basically, Scala Native uses scalafmt and has a similar style to Scala.js as Scala Native followed and leveraged off of Scala.js. We are trying to upgrade but running into large diffs. If we could get a few things then we could upgrade and it might be closer for perhaps Scala.js being able to adopt as well. I can't speak for the project but there have been some attempts to try.
Eric K Richardson
@ekrich
It seems that format: off / format: on is not respected inside java/scaladoc for ascii art.
1 reply
Eric K Richardson
@ekrich
Now that Scalafmt can wrap docs, maybe this would be a good idea.
@kitbellew Would that be hard?
Eric K Richardson
@ekrich
Is this still valid - works but not seeing it in the docs.
project.excludeFilters = [
  scalalib/
]
2 replies
Eric K Richardson
@ekrich
@kitbellew Shouldn't something like this be default prior to the format here based on significant whitespace because you need the line after the foreach?
-    times.foreach {
-      case (k, v) =>
-        val key = k.split(":")(1)
-        totalTimes(key) = totalTimes.getOrElse(key, 0L) + v
-        totalThreads(key) = totalThreads.getOrElse(key, 0L) + 1
+    times.foreach { case (k, v) =>
+      val key = k.split(":")(1)
+      totalTimes(key) = totalTimes.getOrElse(key, 0L) + v
+      totalThreads(key) = totalThreads.getOrElse(key, 0L) + 1
13 replies
Eric K Richardson
@ekrich
I noticed that implicit a => after a higher order function with a control block is fine in Scala 3 but the case needs to be on the next line. So it seems to me the multilineCaseOnly may be good choice.
Eric K Richardson
@ekrich
The above is me answering on mobile - you can't keep it in the same thread.
heksenlied
@heksenlied:matrix.org
[m]
Is it possible to do rewrite to Scala 3 syntax under Scala213Source3 dialect?
Albert Meltzer
@kitbellew
@heksenlied:matrix.org no, most of the rewrites require actual scala 3 and optional braces support.
Eric K Richardson
@ekrich
@kitbellew I followed up over here because it has more to it than just what I was talking to you about. :point_up: May 25, 2021 7:36 AM
Ugo Matrangolo
@umatrangolo

Hi. I’m trying to align constructor arguments for a class like:

case class Foo(
  firstParam: Int,
  secondParam: String,
  thirdParam: Boolean 
)

to something where all type names are aligned vertically.

Reading the documentation looks like I have to define a:

align.tokens.add = [ { code = ":", owner = " ??? " }]

Can’ t find the correct owner bit tough. Sticking this into AST explorer looks like
I have to use Term.Param that works but works also for everything else outside
classes.

How can I tell Scalafmt to apply this formatting rule only to terms inside a case class. Tried

Defn.Class.Ctor.Primary.Term.Param

wout success. I presume is not the right way to nest AST node names.

2 replies
Eric K Richardson
@ekrich
@kitbellew Thanks for the help. I think this is good PR - scala-native/scala-native#2315
Eric K Richardson
@ekrich
@tgodzik Did we get all the libraries ported that are needed for Scala Native scalafmt? We did the ones for metaconfig, looks like scalameta is ready? Any other blockers?
jayzhee
@jayzhee
Does ScalaFMT support Scala 3? I have my configuration version set to 3.0.0-RC3, but attempting to run sbt scalafmtAll will show a bunch of errors when I use Scala 3 features like significant indentation, or transparent inline defs
jayzhee
@jayzhee
For example (this was taken from the scala forums): https://scastie.scala-lang.org/Er8YVwOOQo2z5WyCDMhTxg
I have this in a package called newtype, and in a file called package.scala.
This shows the following messages when running sbt scalafmtAll:
[error] scala/scala3-test/src/main/scala/newtype/package.scala:5: error: expected class or object definition identifier
[error] open class NewType[A]:
[error] ^: scala/scala3-test/src/main/scala/newtype/package.scala
[error] (Compile / scalafmt) scala/newtype/package.scala:5: error: expected class or object definition identifier
[error] open class NewType[A]:
[error] ^: scala/scala3-test/src/main/scala/newtype/package.scala
[error] Total time: 2 s, completed May 28, 2021 2:15:09 AM
Fabrizio Colonna
@ColOfAbRiX
try by adding runner.dialect = scala3
jayzhee
@jayzhee
That did it, thanks a bunch!!
vimalaguti
@vimalaguti

Hi, couldn't find in the doc, in the method def do you know how to align the parameters to the parentheses?

def wuff(
        a: Int,
        b: Int
        )

in intellij formatter it's called "indent first parameter if on new line" + "align when multiline"

5 replies